You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3.10 introduces the X | Y syntax for type annotations. Within function and variable annotations, Mypy in 3.10 treats X | Y as identical to Union[X, Y]. Within type aliases, however, it doesn't do so within subscripts to list, dict, and Callable types.
I would not expect an error from any alias testcase that doesn't arise in the corresponding annotation test case.
Actual Behavior
ListAliasTest raises the following errors:
Type expected within [...]
Invalid type alias: expression is not a valid type
Value of type "Type[List[Any]]" is not indexable
DictAliasTest is the same, just "Type[Dict[Any]]" instead of "Type[List[Any]]". CallableAliasTest raises just the "not a valid type" error.
If this isn't a bug, and there is some reason for the | operator to be, when used in subscripts within type aliases, an exception from the general assumption that X | Y == Union[X, Y], there should be a clearer error message explaining why this doesn't work.
This is my first bug report here, so apologies in advance if I've done anything wrong, and please let me know if there's anything I've forgotten to include.
Your Environment
Mypy version used: 0.910
Mypy command-line flags: --ignore-missing-imports --follow-imports=silent --show-column-numbers (same with or without --strict)
Python version used: 3.10.0b4; was the same on 3.10.0b1
Operating system and version: Windows 10 Home, 10.0.19042 Build 19042
The text was updated successfully, but these errors were encountered:
Bug Report
3.10 introduces the
X | Y
syntax for type annotations. Within function and variable annotations, Mypy in 3.10 treatsX | Y
as identical toUnion[X, Y]
. Within type aliases, however, it doesn't do so within subscripts tolist
,dict
, andCallable
types.To Reproduce
In 3.10:
Expected Behavior
I would not expect an error from any alias testcase that doesn't arise in the corresponding annotation test case.
Actual Behavior
ListAliasTest raises the following errors:
DictAliasTest is the same, just
"Type[Dict[Any]]"
instead of"Type[List[Any]]"
. CallableAliasTest raises just the "not a valid type" error.If this isn't a bug, and there is some reason for the
|
operator to be, when used in subscripts within type aliases, an exception from the general assumption thatX | Y
==Union[X, Y]
, there should be a clearer error message explaining why this doesn't work.This is my first bug report here, so apologies in advance if I've done anything wrong, and please let me know if there's anything I've forgotten to include.
Your Environment
The text was updated successfully, but these errors were encountered: