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)
Are type aliases supported with the new union syntax? I am getting Unsupported left operand type for | ("Type[int]") for something like Expr = int | str
Activity
hauntsaninja commented on Jan 22, 2021
Should also make sure to test base classes: class C(A[int | None]): ... and aliases X = int | str
Support union type syntax in type applications, aliases and casts
Support union type syntax in runtime contexts (#10770)
Support new union syntax in stubs always in runtime context
Support new union syntax in stubs always in runtime context (#10771)
Support new union type syntax with isinstance
Support new union type syntax with isinstance (#10775)
saulshanabrook commented on Aug 2, 2022
Are type aliases supported with the new union syntax? I am getting Unsupported left operand type for | ("Type[int]") for something like Expr = int | str
asottile commented on Aug 2, 2022
works fine for me:
note that mypy here is installed to python3.10 -- you may need to do that or use the python version setting
saulshanabrook commented on Aug 2, 2022
Thanks, yeah was set to a different python version, sorry about that.