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
As a follow-up to #15070, display union types using the new X | Y syntax in error messages when targeting Python 3.10 or later.
Examples:
Instead of Union[int, str], display int | str.
Instead of Optional[str], display str | None
If there is None in a union type, perhaps always display the None as the final item. This way we'd never show a type like None | str (even if type inference would produce this internal representation), since it's not idiomatic.
Generalize the implementation technique used in #15070, which added a version check for using list[x] instead of List[x] in error messages on Python 3.9 and later. In particular, use the hidden command line option in tests to always use the old syntax, so that tests will run consistently. Add specific test cases that enable the X | Y syntax only in the new tests that test this syntax.
The text was updated successfully, but these errors were encountered:
This should fix#15082:
If the python version is set to 3.10 or later union error reports are
going to be displayed using the `X | Y` syntax.
If None is found in a union it is shown as the last element in order to
improve visibility (`Union[bool, None, str]` becomes `"bool | str |
None"`.
To achieve this an option `use_or_syntax()` is created that is set to
true if the python version is 3.10 or later.
For testing a hidden flag --force-union-syntax is used that sets the
option to false.
As a follow-up to #15070, display union types using the new
X | Y
syntax in error messages when targeting Python 3.10 or later.Examples:
Union[int, str]
, displayint | str
.Optional[str]
, displaystr | None
If there is
None
in a union type, perhaps always display theNone
as the final item. This way we'd never show a type likeNone | str
(even if type inference would produce this internal representation), since it's not idiomatic.Generalize the implementation technique used in #15070, which added a version check for using
list[x]
instead ofList[x]
in error messages on Python 3.9 and later. In particular, use the hidden command line option in tests to always use the old syntax, so that tests will run consistently. Add specific test cases that enable theX | Y
syntax only in the new tests that test this syntax.The text was updated successfully, but these errors were encountered: