BaseModel method type annotations cause typing.get_type_hints to raise NameError #7623
Closed
1 task done
Labels
bug V2
Bug related to Pydantic V2
Initial Checks
Description
While using a project like autodoc_pydantic and Sphinx, it uses sphinx-autodoc-typehints and ultimately the stdlib typing.get_type_hints method to inspect pydantic models, their methods, etc. It seems that the type annotations that pydantic is advertising are incomplete/incorrect, causing
NameError
exceptions when callingget_type_hints
, even natively from the Python REPL.Seems like the annotations need to be fully-qualified or some other similar solution? It may also be because of the conditional around
typing.TYPE_CHECKING
when defining type vars like Model,IncEx
,Literal
(fromtyping_extensions
), etc.For background, ideally need compatibility from Python 3.8-3.11+.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: