Skip to content

Commit

Permalink
Improve NewType
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed May 24, 2023
1 parent 6d82a33 commit a6d0aaf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
9 changes: 7 additions & 2 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ from typing import ( # noqa: Y022,Y039
DefaultDict as DefaultDict,
Deque as Deque,
Mapping,
NewType as NewType,
NoReturn as NoReturn,
Sequence,
SupportsAbs as SupportsAbs,
Expand Down Expand Up @@ -198,10 +197,11 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
@abc.abstractmethod
def __index__(self) -> int: ...

# New things in 3.10
# New and changed things in 3.10
if sys.version_info >= (3, 10):
from typing import (
Concatenate as Concatenate,
NewType as NewType,
ParamSpecArgs as ParamSpecArgs,
ParamSpecKwargs as ParamSpecKwargs,
TypeAlias as TypeAlias,
Expand All @@ -226,6 +226,11 @@ else:
TypeGuard: _SpecialForm
def is_typeddict(tp: object) -> bool: ...

class NewType:
def __init__(self, name: str, tp: Any) -> None: ...
def __call__(self, __x: _T) -> _T: ...
__supertype__: type

# New things in 3.11
# NamedTuples are not new, but the ability to create generic NamedTuples is new in 3.11
if sys.version_info >= (3, 11):
Expand Down
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,3 @@ typing_extensions\.reveal_type

# Doesn't exist at runtime
typing\.Protocol

# Function at runtime; we pretend it's already a class
typing_extensions\.NewType
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,3 @@ types.WrapperDescriptorType.__get__
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type

# Function at runtime; we pretend it's already a class
typing_extensions\.NewType
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,3 @@ types.WrapperDescriptorType.__get__
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type

# Function at runtime; we pretend it's already a class
typing_extensions\.NewType

0 comments on commit a6d0aaf

Please sign in to comment.