`TYPE_CHECKING` warnings when subclassing `textual` objects
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
Problem Description
I am seeing the same problem reported in #648 but when dealing with classes from the textual package. I am using the latest pdoc (14.5.0) so the fix from #649 does not appear to have resolved this for all potential third-party packages.
I am not sure what could be different about textual that would potentially cause this behavior to differ from the other case.
Steps to reproduce the behavior:
- Create a new Python venv and install
pdoc==14.5.0andtextual==0.63.5. - Save the following contents to
pdoc-bug-695.py:
from textual.widgets import Static
class Foo(Static):
...
- Run
pdoc pdoc-bug-695.pyand observe the warnings upon loading the HTML page:
Warn: Failed to run TYPE_CHECKING code while parsing dict[type[Message], list[tuple[Callable, str | None]]] type annotation for textual.dom.DOMNode._decorated_handlers: No module named '_typeshed' (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:132)
Warn: Error parsing type annotation dict[type[Message], list[tuple[Callable, str | None]]] for textual.dom.DOMNode._decorated_handlers. Import of Message failed: name 'Message' is not defined (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:148)
Warn: Failed to run TYPE_CHECKING code while parsing Sequence['Widget'] type annotation for pdoc-bug-695.Foo.children: No module named '_typeshed' (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:132)
Warn: Error parsing type annotation Sequence['Widget'] for pdoc-bug-695.Foo.children. Import of Widget failed: name 'Widget' is not defined (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:148)
Warn: Failed to run TYPE_CHECKING code while parsing 'Screen[object]' type annotation for pdoc-bug-695.Foo.screen: No module named '_typeshed' (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:132)
Warn: Error parsing type annotation 'Screen[object]' for pdoc-bug-695.Foo.screen. Import of Screen failed: name 'Screen' is not defined (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:148)
Warn: Failed to run TYPE_CHECKING code while parsing list[Widget] type annotation for pdoc-bug-695.Foo.displayed_children: No module named '_typeshed' (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:132)
Warn: Error parsing type annotation list[Widget] for pdoc-bug-695.Foo.displayed_children. Import of Widget failed: name 'Widget' is not defined (/home/max/sandbox/python/.direnv/python-3.12/lib/python3.12/site-packages/pdoc/doc_types.py:148)
System Information
Paste the output of "pdoc --version" here.
pdoc: 14.5.0
Python: 3.12.3
Platform: Linux-6.9.1-arch1-2-x86_64-with-glibc2.39
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 issue with pdoc 14.5.0 and textual 0.63.5 using the supplied Foo example and pdoc command. Start in pdoc/doc_types.py around the TYPE_CHECKING handling at lines 132 and 148, then trace how the annotations are parsed. Done means subclassing the textual object no longer produces the reported TYPE_CHECKING and annotation warnings.
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