tox-dev / sphinx-autodoc-typehints

Type hints support for the Sphinx autodoc extension
MIT License
561 stars 107 forks source link

Can't use `_typeshed` in TYPE_CHECKING block #479

Open nineteendo opened 2 months ago

nineteendo commented 2 months ago

Example:

if TYPE_CHECKING:
    from _typeshed import StrPath

def foo(path: StrPath) -> StrPath:
    return path

Output (fails a build on read the docs):

WARNING: Failed guarded type import with ModuleNotFoundError("No module named '_typeshed'")

Stubs for _typeshed: https://github.com/python/typeshed/tree/main/stdlib/_typeshed

gaborbernat commented 2 months ago

I do not see how we can solve this, but if someone has ideas PR welcome. I would say for now do not use _typeshed imports.

nineteendo commented 2 months ago

Yeah, unless this can be implemented without executing the code block?

gaborbernat commented 2 months ago

The code block needs to be executed, otherwise we wouldn't be able to resolve some of the objects.