mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
fix UnionType.__or__ and add UnionType.__getitem__ (#14687)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
+11
-2
@@ -717,10 +717,19 @@ if sys.version_info >= (3, 10):
|
||||
def __args__(self) -> tuple[Any, ...]: ...
|
||||
@property
|
||||
def __parameters__(self) -> tuple[Any, ...]: ...
|
||||
def __or__(self, value: Any, /) -> UnionType: ...
|
||||
def __ror__(self, value: Any, /) -> UnionType: ...
|
||||
# `(int | str) | Literal["foo"]` returns a generic alias to an instance of `_SpecialForm` (`Union`).
|
||||
# Normally we'd express this using the return type of `_SpecialForm.__ror__`,
|
||||
# but because `UnionType.__or__` accepts `Any`, type checkers will use
|
||||
# the return type of `UnionType.__or__` to infer the result of this operation
|
||||
# rather than `_SpecialForm.__ror__`. To mitigate this, we use `| Any`
|
||||
# in the return type of `UnionType.__(r)or__`.
|
||||
def __or__(self, value: Any, /) -> UnionType | Any: ...
|
||||
def __ror__(self, value: Any, /) -> UnionType | Any: ...
|
||||
def __eq__(self, value: object, /) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
# you can only subscript a `UnionType` instance if at least one of the elements
|
||||
# in the union is a generic alias instance that has a non-empty `__parameters__`
|
||||
def __getitem__(self, parameters: Any) -> object: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
@final
|
||||
|
||||
Reference in New Issue
Block a user