Skip to content
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

Fix new style union syntax in type aliases #14008

Merged
merged 14 commits into from
Nov 7, 2022
Merged

Fix new style union syntax in type aliases #14008

merged 14 commits into from
Nov 7, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Nov 4, 2022

Fix Python 3.10 | union syntax in type aliases, when one of
the operands is a type alias or a type with an overloaded __init__.

Fixes #12368. Fixes #12005. Fixes #11426.

@@ -0,0 +1,35 @@
from typing import Generic, TypeVar, Callable, Any, Mapping
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some tests were using the typeshed stub for functools, and it requires typing._SpecialForm. Instead of adding a bunch of typing-medium.pyi fixtures, I decided to create a simplified stub to use in tests. This also speeds up the test cases a bit.

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

pandas looks like a real issue, they probably meant to do _truthy_value: Scalar instead of _truthy_value = Scalar in the base class

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

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

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/annotations.py:1064: error: Dict entry 6 has incompatible type "object": "Tuple[ToUser, ToRole]"; expected "Type[Any]": "Tuple[Union[Callable[[str], Coroutine[Any, Any, Any]], Callable[[str], Any]], ...]"  [dict-item]
+ tanjun/annotations.py:1064: error: Dict entry 6 has incompatible type "<typing special form>": "Tuple[ToUser, ToRole]"; expected "Type[Any]": "Tuple[Union[Callable[[str], Coroutine[Any, Any, Any]], Callable[[str], Any]], ...]"  [dict-item]
- tanjun/annotations.py:1072: error: List item 4 has incompatible type "object"; expected "Type[Any]"  [list-item]
+ tanjun/annotations.py:1072: error: List item 4 has incompatible type "<typing special form>"; expected "Type[Any]"  [list-item]
- tanjun/annotations.py:1247: error: Dict entry 6 has incompatible type "object": "Callable[[_ArgConfig, SlashCommand[Any], str], Self?]"; expected "Type[Any]": "Callable[[_ArgConfig, SlashCommand[Any], str], SlashCommand[Any]]"  [dict-item]
+ tanjun/annotations.py:1247: error: Dict entry 6 has incompatible type "<typing special form>": "Callable[[_ArgConfig, SlashCommand[Any], str], Self?]"; expected "Type[Any]": "Callable[[_ArgConfig, SlashCommand[Any], str], SlashCommand[Any]]"  [dict-item]

discord.py (https://github.com/Rapptz/discord.py)
- discord/app_commands/transformers.py:728: error: Dict entry 0 has incompatible type "AppCommandOptionType": "Tuple[Type[str], object]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
+ discord/app_commands/transformers.py:728: error: Dict entry 0 has incompatible type "AppCommandOptionType": "Tuple[Type[str], <typing special form>]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
- discord/app_commands/transformers.py:729: error: Dict entry 1 has incompatible type "AppCommandOptionType": "Tuple[Type[int], object]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
+ discord/app_commands/transformers.py:729: error: Dict entry 1 has incompatible type "AppCommandOptionType": "Tuple[Type[int], <typing special form>]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
- discord/app_commands/transformers.py:730: error: Dict entry 2 has incompatible type "AppCommandOptionType": "Tuple[Type[bool], object]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
+ discord/app_commands/transformers.py:730: error: Dict entry 2 has incompatible type "AppCommandOptionType": "Tuple[Type[bool], <typing special form>]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
- discord/app_commands/transformers.py:731: error: Dict entry 3 has incompatible type "AppCommandOptionType": "Tuple[Type[float], object]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
+ discord/app_commands/transformers.py:731: error: Dict entry 3 has incompatible type "AppCommandOptionType": "Tuple[Type[float], <typing special form>]"; expected "AppCommandOptionType": "Tuple[Type[Any], ...]"  [dict-item]
- discord/app_commands/transformers.py:738: error: Incompatible default for argument "_none" (default has type "object", argument has type "type")  [assignment]
+ discord/app_commands/transformers.py:738: error: Incompatible default for argument "_none" (default has type "<typing special form>", argument has type "type")  [assignment]
- discord/app_commands/commands.py:254: error: Incompatible default for argument "_none" (default has type "object", argument has type "type")  [assignment]
+ discord/app_commands/commands.py:254: error: Incompatible default for argument "_none" (default has type "<typing special form>", argument has type "type")  [assignment]
- discord/ext/commands/converter.py:1177: error: Argument 2 to "issubclass" has incompatible type "_SpecialForm"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]"  [arg-type]
+ discord/ext/commands/converter.py:1177: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]"  [arg-type]

pandera (https://github.com/pandera-dev/pandera)
- pandera/dtypes.py:23: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "typing._SpecialForm")  [assignment]
+ pandera/dtypes.py:23: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "<typing special form>")  [assignment]
- pandera/schemas.py:46: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "typing._SpecialForm")  [assignment]
+ pandera/schemas.py:46: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "<typing special form>")  [assignment]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/integer.py:135: error: Incompatible types in assignment (expression has type "int", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]
+ pandas/core/arrays/integer.py:136: error: Incompatible types in assignment (expression has type "int", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]
+ pandas/core/arrays/floating.py:119: error: Incompatible types in assignment (expression has type "float", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]
+ pandas/core/arrays/floating.py:120: error: Incompatible types in assignment (expression has type "float", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]
+ pandas/core/arrays/boolean.py:290: error: Incompatible types in assignment (expression has type "bool", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]
+ pandas/core/arrays/boolean.py:291: error: Incompatible types in assignment (expression has type "bool", base class "BaseMaskedArray" defined the type as "<typing special form>")  [assignment]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants