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.
This commit is contained in:
Jelle Zijlstra
2022-03-10 22:35:45 -08:00
committed by GitHub
parent a3e62d56fc
commit 9c50fe7b64

View File

@@ -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")