Skip to content

Fixes #21689 - stubgen --inspect-mode crash on PEP 604 unions - #21807

Open
ayushdoesdev wants to merge 2 commits into
python:masterfrom
ayushdoesdev:master
Open

Fixes #21689 - stubgen --inspect-mode crash on PEP 604 unions#21807
ayushdoesdev wants to merge 2 commits into
python:masterfrom
ayushdoesdev:master

Conversation

@ayushdoesdev

Copy link
Copy Markdown

Fixes #21689

stubgen --inspect-mode crashed with AttributeError on PEP 604 union annotations (X | Y), because runtime unions are types.UnionType objects with neither __qualname__ nor __name__, and getattr(typ, "__qualname__", typ.__name__) evaluates the default eagerly.

This change formats types.UnionType as X | Y, maps NoneType to None, and looks up type names safely so inspect-mode stub generation succeeds for these annotations.

cursoragent and others added 2 commits August 4, 2026 14:09
types.UnionType annotations (X | Y) have neither __qualname__ nor
__name__. getattr(..., typ.__name__) also evaluates the default
eagerly, so inspect-mode stubgen crashed with AttributeError.

Format UnionType args as X | Y and map NoneType to None.

Fixes python#21689

Co-authored-by: Ayush Anand Srivastava <ayushdoesdev@users.noreply.github.com>
…inspect-e18d

Fix stubgen --inspect-mode crash on PEP 604 unions
@ayushdoesdev ayushdoesdev changed the title Fixes #21689 Fixes #21689 - stubgen --inspect-mode crash on PEP 604 unions Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stubgen --inspect-mode crashes with AttributeError on PEP 604 union syntax (X | Y) *(mypy 2.1.0)*

2 participants