KEMBAR78
Remove Optional[...] special-casing during semantic analysis by ilevkivskyi · Pull Request #13357 · python/mypy · GitHub
Skip to content

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