From 050a77d8e31f4fc161f29e89a9cfc54015bb8d88 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 3 Dec 2021 12:33:44 +0000 Subject: [PATCH] Make `NewType` a class in 3.10 (#6469) --- stdlib/typing.pyi | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index f27f87a06..a56ea8c8c 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -83,6 +83,15 @@ if sys.version_info >= (3, 10): Concatenate: _SpecialForm = ... TypeAlias: _SpecialForm = ... TypeGuard: _SpecialForm = ... + class NewType: + def __init__(self, name: str, tp: type) -> None: ... + def __call__(self, x: _T) -> _T: ... + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... + __supertype__: type + +else: + def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... # These type variables are used by the container types. _S = TypeVar("_S") @@ -699,8 +708,6 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def __or__(self: _T, __value: _T) -> _T: ... def __ior__(self: _T, __value: _T) -> _T: ... -def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... - # This itself is only available during type checking def type_check_only(func_or_cls: _F) -> _F: ...