You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.12 introduced PEP 695 Type Parameter Syntax. This seems to break type parsing for a forward type reference to a generic class in a method of another generic class:
That is a valid Python 3.12 module, but running pdoc on it will result in: Error parsing type annotation Bar[T] for package.module.Foo.foo. Import of T failed: name 'T' is not defined
The generated HTML therefore does not have a link:
classFoo[T]:
deffoo(self) ->"Bar[T]":
...
classBar[T]:
defbar(self, _: T) ->None:
...
if__name__=="__main__":
importtypingtyping.get_type_hints(Foo.foo) # NameError: name 'T' is not defined
Contributions are welcome, I won't have capacity to look into this anytime soon. :)
That should be fixed by the implementation of PEP649 in Python 3.14, which would bring new attributes to help with TypeVar and PEP695. See section Deferred evaluation of PEP 695 and 696 objects of PEP749 for more details.
This issue can be closed since Python 3.12 or 3.13 do not seem to support this typing style.
Problem Description
Python 3.12 introduced PEP 695 Type Parameter Syntax. This seems to break type parsing for a forward type reference to a generic class in a method of another generic class:
That is a valid Python 3.12 module, but running
pdoc
on it will result in:Error parsing type annotation Bar[T] for package.module.Foo.foo. Import of T failed: name 'T' is not defined
The generated HTML therefore does not have a link:
Steps to reproduce the behavior:
Run
pdoc
on a package containing the example module above.Note that using the old syntax does not break parsing, probably because it requires a
TypeVar
to be defined:Note also that the problem only occurs with a forward reference, insofar as the following example does not break parsing either:
System Information
The text was updated successfully, but these errors were encountered: