Closed dureuill closed 3 years ago
- python version: 3.7.3
In Python <=3.7, typing annotations are evaluated at definition time. In Python 3.8+, they are evaluated only as needed by type checking utilities. Thus, the error NameError: name 'Bar' is not defined
makes sense in your case.
Your options are:
def bar(self) -> 'Bar': ...
from __future__ import annotations
Thank you for the answer, looks like this is due to my version of Python then!
I was misled by mypy actually having a different behavior in this case, apparently.
I will use one of the solutions you proposed and close this issue. Thank you!
Mypy works because it does static code analysis on raw text files, sans execution.
Thank you for maintaining pdoc! I encountered an issue when running the tool on code that can be minimized to the following:
Command line used:
Expected Behavior
I would expect the tool to generate documentation on the example above, with the following output:
At first I doubted that this kind of recursive annotations are actually allowed (I'm pretty new to annotation typing in python3), but it looks like mypy accepts them fine:
Actual Behavior
Steps to Reproduce
Additional info
however, using it makes it so mypy now fails on the code: