pdoc3 / pdoc3/pdoc

Linking stops working with "from __future__ import annotations"

Open
#369 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.2k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the proj/test.py and proj/test2.py examples, comparing behavior with and without the future-annotations import. Start by examining how inspect.signature and typing.get_type_hints interact with f.obj in the pdoc template; done means type links resolve in both cases on the stated Python versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.