Fixes #21689 - stubgen --inspect-mode crash on PEP 604 unions - #21807
Open
ayushdoesdev wants to merge 2 commits into
Open
Fixes #21689 - stubgen --inspect-mode crash on PEP 604 unions#21807ayushdoesdev wants to merge 2 commits into
ayushdoesdev wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21689
stubgen --inspect-modecrashed withAttributeErroron PEP 604 union annotations (X | Y), because runtime unions aretypes.UnionTypeobjects with neither__qualname__nor__name__, andgetattr(typ, "__qualname__", typ.__name__)evaluates the default eagerly.This change formats
types.UnionTypeasX | Y, mapsNoneTypetoNone, and looks up type names safely so inspect-mode stub generation succeeds for these annotations.