Skip to content

Remove Optional[...] special-casing during semantic analysis #13357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2022

Conversation

ilevkivskyi
Copy link
Member

This is another fix for recursive aliases. Ref #13297

Previously this special casing caused Optional[...] to fail with infinite recursion, where Union[..., None] worked. I also delete a duplicate helper, and replace it with another existing one that handles type aliases properly.

(I have no idea why some TypeGuard test started passing, but we have xfail-strict so I am re-enabling this test.)

cc @JukkaL

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2022

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com./Rapptz/discord.py)
- discord/interactions.py:163: error: Incompatible types in assignment (expression has type "object", variable has type "Union[ChatInputApplicationCommandInteractionData, UserApplicationCommandInteractionData, MessageApplicationCommandInteractionData, ButtonMessageComponentInteractionData, SelectMessageComponentInteractionData, ModalSubmitInteractionData, None]")
+ discord/interactions.py:163: error: Incompatible types in assignment (expression has type "object", variable has type "Union[Union[ChatInputApplicationCommandInteractionData, UserApplicationCommandInteractionData, MessageApplicationCommandInteractionData], Union[ButtonMessageComponentInteractionData, SelectMessageComponentInteractionData], ModalSubmitInteractionData, None]")

@ilevkivskyi
Copy link
Member Author

Error message in mypy_primer looks a bit more verbose, but it is because nested unions are aliases. If we will switch to showing alias names instead in error messages, it will be much more compact.

@ilevkivskyi ilevkivskyi merged commit e69bd9a into python:master Aug 8, 2022
@ilevkivskyi ilevkivskyi deleted the fix-optional-rec branch August 8, 2022 10:47
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.

1 participant