From 9c50fe7b6494d6964db2688c72b01e51716e0867 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 10 Mar 2022 22:35:45 -0800 Subject: [PATCH] Fix overly precise `typing.NewType` signature (#7474) `type` is incorrect because `NewType` can also accept another `NewType`: https://peps.python.org/pep-0484/#newtype-helper-function The return type was also wrong; pre-3.10 `NewType()` doesn't return a type object. --- stdlib/typing.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 1f0afb6de..457ad21b7 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -554,14 +554,14 @@ if sys.version_info >= (3, 10): TypeGuard: _SpecialForm class NewType: - def __init__(self, name: str, tp: type) -> None: ... + def __init__(self, name: str, tp: Any) -> 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]: ... + def NewType(name: str, tp: Any) -> Any: ... # These type variables are used by the container types. _S = TypeVar("_S")