Skip to content

Fix stubgen --inspect-mode crash on PEP 604 unions - #1

Merged
ayushdoesdev merged 1 commit into
masterfrom
cursor/fix-stubgen-uniontype-inspect-e18d
Aug 4, 2026
Merged

Fix stubgen --inspect-mode crash on PEP 604 unions#1
ayushdoesdev merged 1 commit into
masterfrom
cursor/fix-stubgen-uniontype-inspect-e18d

Conversation

@ayushdoesdev

@ayushdoesdev ayushdoesdev commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Fixes python#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.

Open in Web Open in Cursor 

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>
@ayushdoesdev
ayushdoesdev marked this pull request as ready for review August 4, 2026 14:10
@ayushdoesdev
ayushdoesdev merged commit bbdb27f into master 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