Skip to content

TYPE_CHECKING warnings when subclassing textual objects #695

@mrossinek

Description

@mrossinek

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:

  1. Create a new Python venv and install pdoc==14.5.0 and textual==0.63.5.
  2. Save the following contents to pdoc-bug-695.py:
from textual.widgets import Static

class Foo(Static):
    ...
  1. Run pdoc pdoc-bug-695.py and 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions