-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Support PEP 604 syntax for runtime use cases #9880
Comments
Should also make sure to test base classes: |
These are only available in Python 3.10 mode. Work on #9880.
Support the X | Y syntax (PEP 604) in type aliases, casts, type applications and base classes. These are only available in Python 3.10 mode and probably won't work in stubs when targeting earlier Python versions yet. Work on #9880.
Previously it only worked when the target Python version was 3.10. Work on #9880.
Previously it only worked when the target Python version was 3.10. Now type aliases like these work in stubs on all Python versions: ``` A = str | None ``` Since type objects don't support `__or__` before 3.10 (in typeshed), skip some type checking of type alias definitions in stubs. Defensively only skip these things in stubs, even though they could be redundant in other contexts as well. Work on #9880.
Support things like `isinstance(x, int | str)` in Python 3.10 Closes #9880.
Support things like `isinstance(x, int | str)` in Python 3.10 Closes #9880.
Are type aliases supported with the new union syntax? I am getting |
works fine for me: $ mypy t.py
Success: no issues found in 1 source file
$ cat t.py
X = int | str
def f(x: X) -> X:
return x
f(1)
f('2')
$ mypy --version
mypy 0.971 (compiled: yes) note that |
Thanks, yeah was set to a different python version, sorry about that. |
This is a follow up to #9610.
Most of PEP 604 support is available, however we're missing support for
isinstance(x, int | str)
(and more generally, runtime uses of__or__
on types). This will require a typeshed change, but I'm filing here so that we make sure it works. Even if all it takes is a typeshed change, at the very least we should add a test.(For people who stumble upon this thread, this is only relevant for Python 3.10 and greater)
The text was updated successfully, but these errors were encountered: