pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.12k stars 145 forks source link

Linking stops working with "from __future__ import annotations" #369

Open blaisethom opened 2 years ago

blaisethom commented 2 years ago

When using "from future import annotations", linking of types stops working. I believe this is because the behaviour of inspect.signature changes to returning only the string form of the class reference as in the code, and so pdoc3 no longer finds the package name.

For example, setting proj/test.py as:

class MyClass:
    def func2(x: int):
        return x

and proj/test.py as:

#from __future__ import annotations

from proj.test2 import MyClass

def func(x: MyClass):
    """My new docstring"""
    return x

Will have the linking work, but if you uncomment the "from future" import it no longer works

Expected Behavior

Linking works with future annotations.

Actual Behavior

Linking stops working with future annotations.

Additional info

Some early prototyping within a notebook suggests that typing.get_type_hints does still get the fully qualified name if the classes are imported in the notebook, but I've been unable so far to get that to work using f.obj within a pdoc template.