Fix new style union syntax in type aliases#14008
Merged
Conversation
JukkaL
commented
Nov 4, 2022
| @@ -0,0 +1,35 @@ | |||
| from typing import Generic, TypeVar, Callable, Any, Mapping | |||
Collaborator
Author
There was a problem hiding this comment.
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.
ilevkivskyi
approved these changes
Nov 4, 2022
This comment has been minimized.
This comment has been minimized.
Collaborator
|
pandas looks like a real issue, they probably meant to do |
hauntsaninja
approved these changes
Nov 4, 2022
Contributor
|
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]
|
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.
Fix Python 3.10
|union syntax in type aliases, when one ofthe operands is a type alias or a type with an overloaded
__init__.Fixes #12368. Fixes #12005. Fixes #11426.