Skip to content

Commit a6d0aaf

Browse files
committed
Improve NewType
1 parent 6d82a33 commit a6d0aaf

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

stdlib/typing_extensions.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ from typing import ( # noqa: Y022,Y039
2222
DefaultDict as DefaultDict,
2323
Deque as Deque,
2424
Mapping,
25-
NewType as NewType,
2625
NoReturn as NoReturn,
2726
Sequence,
2827
SupportsAbs as SupportsAbs,
@@ -198,10 +197,11 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
198197
@abc.abstractmethod
199198
def __index__(self) -> int: ...
200199

201-
# New things in 3.10
200+
# New and changed things in 3.10
202201
if sys.version_info >= (3, 10):
203202
from typing import (
204203
Concatenate as Concatenate,
204+
NewType as NewType,
205205
ParamSpecArgs as ParamSpecArgs,
206206
ParamSpecKwargs as ParamSpecKwargs,
207207
TypeAlias as TypeAlias,
@@ -226,6 +226,11 @@ else:
226226
TypeGuard: _SpecialForm
227227
def is_typeddict(tp: object) -> bool: ...
228228

229+
class NewType:
230+
def __init__(self, name: str, tp: Any) -> None: ...
231+
def __call__(self, __x: _T) -> _T: ...
232+
__supertype__: type
233+
229234
# New things in 3.11
230235
# NamedTuples are not new, but the ability to create generic NamedTuples is new in 3.11
231236
if sys.version_info >= (3, 11):

tests/stubtest_allowlists/py37.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,3 @@ typing_extensions\.reveal_type
159159

160160
# Doesn't exist at runtime
161161
typing\.Protocol
162-
163-
# Function at runtime; we pretend it's already a class
164-
typing_extensions\.NewType

tests/stubtest_allowlists/py38.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,3 @@ types.WrapperDescriptorType.__get__
174174
typing_extensions\.assert_never
175175
typing_extensions\.assert_type
176176
typing_extensions\.reveal_type
177-
178-
# Function at runtime; we pretend it's already a class
179-
typing_extensions\.NewType

tests/stubtest_allowlists/py39.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,3 @@ types.WrapperDescriptorType.__get__
170170
typing_extensions\.assert_never
171171
typing_extensions\.assert_type
172172
typing_extensions\.reveal_type
173-
174-
# Function at runtime; we pretend it's already a class
175-
typing_extensions\.NewType

0 commit comments

Comments
 (0)