@@ -717,10 +717,19 @@ if sys.version_info >= (3, 10):
717717 def __args__ (self ) -> tuple [Any , ...]: ...
718718 @property
719719 def __parameters__ (self ) -> tuple [Any , ...]: ...
720- def __or__ (self , value : Any , / ) -> UnionType : ...
721- def __ror__ (self , value : Any , / ) -> UnionType : ...
720+ # `(int | str) | Literal["foo"]` returns a generic alias to an instance of `_SpecialForm` (`Union`).
721+ # Normally we'd express this using the return type of `_SpecialForm.__ror__`,
722+ # but because `UnionType.__or__` accepts `Any`, type checkers will use
723+ # the return type of `UnionType.__or__` to infer the result of this operation
724+ # rather than `_SpecialForm.__ror__`. To mitigate this, we use `| Any`
725+ # in the return type of `UnionType.__(r)or__`.
726+ def __or__ (self , value : Any , / ) -> UnionType | Any : ...
727+ def __ror__ (self , value : Any , / ) -> UnionType | Any : ...
722728 def __eq__ (self , value : object , / ) -> bool : ...
723729 def __hash__ (self ) -> int : ...
730+ # you can only subscript a `UnionType` instance if at least one of the elements
731+ # in the union is a generic alias instance that has a non-empty `__parameters__`
732+ def __getitem__ (self , parameters : Any ) -> object : ...
724733
725734if sys .version_info >= (3 , 13 ):
726735 @final
0 commit comments