KEMBAR78
Support new union syntax in stubs always in runtime context by JukkaL · Pull Request #10771 · python/mypy · GitHub
Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 6, 2021

Previously it only worked when the target Python version was 3.10. Now type
aliases like these work in stubs on all Python versions:

A = str | None

Since type objects don't support __or__ before 3.10 (in typeshed), skip some
type checking of type alias definitions in stubs. Defensively only skip these things
in stubs, even though they could be redundant in other contexts as well.

Work on #9880.

JukkaL added 4 commits July 6, 2021 14:23
Previously it only worked when the target Python version was 3.10.

Work on #9880.
self.nesting_level = 0
# Should we allow unnormalized types like `list[int]`
# (currently allowed in stubs)?
self.allow_unnormalized = allow_unnormalized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment above to reflect the new name?

accept_items(e.left)
accept_items(e.right)
else:
self.expr_checker.accept(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I am not sure how this logic work correctly for A = list[int | None], maybe add a short comment?

@JukkaL JukkaL merged commit 53836bd into master Jul 6, 2021
@JukkaL JukkaL deleted the union-stubs branch July 6, 2021 17:40
@AlexWaygood AlexWaygood added the topic-pep-604 PEP 604 (union | operator) label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-pep-604 PEP 604 (union | operator)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants