Forward references break with NamedTuples
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
Problem Description
Thanks for this library! Hopefully this is an easy one: Forward references inside NamedTuples do not get resolved and result in a warning
Steps to reproduce the behavior:
from __future__ import annotations
from typing import NamedTuple
class Foo(NamedTuple):
b: Bar
class Bar:
pass
Results in:
Warn: Error parsing type annotation ForwardRef('Bar') for bug.Foo.__init__. Import of Bar failed: name 'Bar' is not defined
It appears to just be NamedTuples -- regular classes (and dataclasses) do not produce this warning.
System Information
pdoc: 15.0.1
Python: 3.10.8
Platform: Linux-5.15.0-125-generic-x86_64-with-glibc2.31
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the warning with the provided Python NamedTuple example, then trace pdoc's handling of NamedTuple annotations and ForwardRef values. Verify that the forward reference resolves without a warning while regular classes and dataclasses remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100