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
PEP604 allows | to be used for union types. you can now write str | int instead of Union[str, int] or str | None instead of Optional[str] and even isinstance(foo, str | int) will work. This feature is accepted for Python 3.10, but you can use it already with mypy>=0.800 and from __future__ import annotations (which will become the default in Python 3.10 as well).
A workaround is to write type declarations as strings like "str | None" or "str | int".
How it should be
The | operator will be used a lot in future Python versions (e.g. Structural Pattern Matching uses it to define or-patterns). So I think this rule should not cause a violation for these special cases.
Bug report
What's wrong
PEP604 allows
|
to be used for union types. you can now writestr | int
instead ofUnion[str, int]
orstr | None
instead ofOptional[str]
and evenisinstance(foo, str | int)
will work. This feature is accepted for Python 3.10, but you can use it already with mypy>=0.800 andfrom __future__ import annotations
(which will become the default in Python 3.10 as well).However, currently this syntax triggers WPS465.
A workaround is to write type declarations as strings like
"str | None"
or"str | int"
.How it should be
The
|
operator will be used a lot in future Python versions (e.g. Structural Pattern Matching uses it to define or-patterns). So I think this rule should not cause a violation for these special cases.System information
OS: Ubuntu 18.04.5 LTS x86_64
Python: 3.7.9
pip: 21.0.1
flake8 information
The text was updated successfully, but these errors were encountered: