Merge typing.Union
and types.UnionType
· Issue #105499 · python/cpython (original) (raw)
Currently, unions created through typing.Union[A, B]
and through the PEP-604 syntax A | B
are at runtime instances of completely different types, and they differ in exactly what elements they accept. This is confusing and makes it harder for users to detect unions at runtime.
I propose to proceed in two steps:
- Make
typing.Union
an alias fortypes.UnionType
and make it sotypes.UnionType[A, B]
works, accepting the same typesUnion
accepts now. - Loosen the rules for what the
|
operator accepts to accept more types that are commonly used in unions.