tox-dev / sphinx-autodoc-typehints

Type hints support for the Sphinx autodoc extension
MIT License
560 stars 106 forks source link

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

Open nineteendo opened 1 month ago

nineteendo commented 1 month 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 1 month 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 1 month ago

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

gaborbernat commented 1 month ago

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