Skip to content

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

Open
@blaisethom

Description

@blaisethom

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

  • pdoc version: 0.10.0
  • python versions tested: 3.8.12 and 3.10.0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions