@@ -17,7 +17,7 @@ from collections.abc import (
1717 ValuesView ,
1818)
1919from importlib .machinery import ModuleSpec
20- from typing import Any , ClassVar , Literal , ParamSpec , TypeVar , final , overload
20+ from typing import Any , ClassVar , Literal , ParamSpec , TypeVar , Union , final , overload
2121from typing_extensions import Self , TypeAliasType , TypeVarTuple , deprecated , disjoint_base
2222
2323if sys .version_info >= (3 , 14 ):
@@ -719,25 +719,28 @@ class EllipsisType: ...
719719@final
720720class NotImplementedType (Any ): ...
721721
722- @final
723- class UnionType :
724- @property
725- def __args__ (self ) -> tuple [Any , ...]: ...
726- @property
727- def __parameters__ (self ) -> tuple [Any , ...]: ...
728- # `(int | str) | Literal["foo"]` returns a generic alias to an instance of `_SpecialForm` (`Union`).
729- # Normally we'd express this using the return type of `_SpecialForm.__ror__`,
730- # but because `UnionType.__or__` accepts `Any`, type checkers will use
731- # the return type of `UnionType.__or__` to infer the result of this operation
732- # rather than `_SpecialForm.__ror__`. To mitigate this, we use `| Any`
733- # in the return type of `UnionType.__(r)or__`.
734- def __or__ (self , value : Any , / ) -> UnionType | Any : ...
735- def __ror__ (self , value : Any , / ) -> UnionType | Any : ...
736- def __eq__ (self , value : object , / ) -> bool : ...
737- def __hash__ (self ) -> int : ...
738- # you can only subscript a `UnionType` instance if at least one of the elements
739- # in the union is a generic alias instance that has a non-empty `__parameters__`
740- def __getitem__ (self , parameters : Any , / ) -> object : ...
722+ if sys .version_info >= (3 , 14 ):
723+ UnionType = Union
724+ else :
725+ @final
726+ class UnionType :
727+ @property
728+ def __args__ (self ) -> tuple [Any , ...]: ...
729+ @property
730+ def __parameters__ (self ) -> tuple [Any , ...]: ...
731+ # `(int | str) | Literal["foo"]` returns a generic alias to an instance of `_SpecialForm` (`Union`).
732+ # Normally we'd express this using the return type of `_SpecialForm.__ror__`,
733+ # but because `UnionType.__or__` accepts `Any`, type checkers will use
734+ # the return type of `UnionType.__or__` to infer the result of this operation
735+ # rather than `_SpecialForm.__ror__`. To mitigate this, we use `| Any`
736+ # in the return type of `UnionType.__(r)or__`.
737+ def __or__ (self , value : Any , / ) -> UnionType | Any : ...
738+ def __ror__ (self , value : Any , / ) -> UnionType | Any : ...
739+ def __eq__ (self , value : object , / ) -> bool : ...
740+ def __hash__ (self ) -> int : ...
741+ # you can only subscript a `UnionType` instance if at least one of the elements
742+ # in the union is a generic alias instance that has a non-empty `__parameters__`
743+ def __getitem__ (self , parameters : Any , / ) -> object : ...
741744
742745if sys .version_info >= (3 , 13 ):
743746 @final
0 commit comments