From ff4bd7c465c2da79753e98020ef3893a5250891b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 5 Dec 2021 23:16:19 +0000 Subject: [PATCH] Add `__(r)or__` to various `typing` classes (#6498) - `__or__` was added to `TypeVar` in Python 3.10: https://bugs.python.org/issue41428 (this PR: https://github.com/python/cpython/pull/21515) - `__or__` was added to `ForwardRef` in Python 3.11: https://bugs.python.org/issue45489 --- stdlib/typing.pyi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index a56ea8c8c..195645af4 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -29,11 +29,17 @@ class TypeVar: covariant: bool = ..., contravariant: bool = ..., ) -> None: ... + if sys.version_info >= (3, 10): + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... _promote = object() class _SpecialForm: def __getitem__(self, typeargs: Any) -> object: ... + if sys.version_info >= (3, 10): + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... _F = TypeVar("_F", bound=Callable[..., Any]) _P = _ParamSpec("_P") @@ -80,6 +86,8 @@ if sys.version_info >= (3, 10): def args(self) -> ParamSpecArgs: ... @property def kwargs(self) -> ParamSpecKwargs: ... + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... Concatenate: _SpecialForm = ... TypeAlias: _SpecialForm = ... TypeGuard: _SpecialForm = ... @@ -727,6 +735,9 @@ if sys.version_info >= (3, 7): def __eq__(self, other: Any) -> bool: ... def __hash__(self) -> int: ... def __repr__(self) -> str: ... + if sys.version_info >= (3, 11): + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... if sys.version_info >= (3, 10): def is_typeddict(tp: Any) -> bool: ...