Skip to content

Commit 185adf0

Browse files
Clean up stubtest allowlist for typing (#10205)
1 parent e4dcfcc commit 185adf0

File tree

8 files changed

+124
-9
lines changed

8 files changed

+124
-9
lines changed

stdlib/typing.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ if sys.version_info >= (3, 11):
211211
NotRequired: _SpecialForm
212212
LiteralString: _SpecialForm
213213

214+
@_final
214215
class TypeVarTuple:
215216
@property
216217
def __name__(self) -> str: ...
@@ -220,16 +221,19 @@ if sys.version_info >= (3, 11):
220221
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...
221222

222223
if sys.version_info >= (3, 10):
224+
@_final
223225
class ParamSpecArgs:
224226
@property
225227
def __origin__(self) -> ParamSpec: ...
226228
def __init__(self, origin: ParamSpec) -> None: ...
227229

230+
@_final
228231
class ParamSpecKwargs:
229232
@property
230233
def __origin__(self) -> ParamSpec: ...
231234
def __init__(self, origin: ParamSpec) -> None: ...
232235

236+
@_final
233237
class ParamSpec:
234238
@property
235239
def __name__(self) -> str: ...
@@ -272,7 +276,7 @@ if sys.version_info >= (3, 10):
272276

273277
class NewType:
274278
def __init__(self, name: str, tp: Any) -> None: ...
275-
def __call__(self, x: _T) -> _T: ...
279+
def __call__(self, __x: _T) -> _T: ...
276280
def __or__(self, other: Any) -> _SpecialForm: ...
277281
def __ror__(self, other: Any) -> _SpecialForm: ...
278282
__supertype__: type

stdlib/typing_extensions.pyi

Lines changed: 15 additions & 4 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,
@@ -97,6 +96,7 @@ __all__ = [
9796
"runtime_checkable",
9897
"Text",
9998
"TypeAlias",
99+
"TypeAliasType",
100100
"TypeGuard",
101101
"TYPE_CHECKING",
102102
"Never",
@@ -106,6 +106,7 @@ __all__ = [
106106
"clear_overloads",
107107
"get_args",
108108
"get_origin",
109+
"get_original_bases",
109110
"get_overloads",
110111
"get_type_hints",
111112
]
@@ -196,30 +197,40 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
196197
@abc.abstractmethod
197198
def __index__(self) -> int: ...
198199

199-
# New things in 3.10
200+
# New and changed things in 3.10
200201
if sys.version_info >= (3, 10):
201202
from typing import (
202203
Concatenate as Concatenate,
204+
NewType as NewType,
203205
ParamSpecArgs as ParamSpecArgs,
204206
ParamSpecKwargs as ParamSpecKwargs,
205207
TypeAlias as TypeAlias,
206208
TypeGuard as TypeGuard,
207209
is_typeddict as is_typeddict,
208210
)
209211
else:
212+
@final
210213
class ParamSpecArgs:
211-
__origin__: ParamSpec
214+
@property
215+
def __origin__(self) -> ParamSpec: ...
212216
def __init__(self, origin: ParamSpec) -> None: ...
213217

218+
@final
214219
class ParamSpecKwargs:
215-
__origin__: ParamSpec
220+
@property
221+
def __origin__(self) -> ParamSpec: ...
216222
def __init__(self, origin: ParamSpec) -> None: ...
217223

218224
Concatenate: _SpecialForm
219225
TypeAlias: _SpecialForm
220226
TypeGuard: _SpecialForm
221227
def is_typeddict(tp: object) -> bool: ...
222228

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

tests/stubtest_allowlists/py310.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,14 @@ dataclasses.KW_ONLY
172172

173173
# We pretend it's a read-only property for forward compatibility with 3.12
174174
typing.ParamSpec(Args|Kwargs).__origin__
175+
176+
# https://github.com/python/mypy/issues/15302
177+
typing_extensions\.assert_never
178+
typing_extensions\.assert_type
179+
typing_extensions\.reveal_type
180+
typing.NewType.__call__
181+
182+
# Super-special typing primitives
183+
typing_extensions\.Final
184+
typing\.NamedTuple
185+
typing\.Annotated

tests/stubtest_allowlists/py311.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ contextlib.AbstractAsyncContextManager.__class_getitem__
126126
contextlib.AbstractContextManager.__class_getitem__
127127

128128
# Super-special typing primitives
129-
typing._SpecialForm.__mro_entries__
129+
typing\._SpecialForm.*
130130
typing._TypedDict.__delitem__
131131
typing._TypedDict.__ior__
132132
typing._TypedDict.__or__
@@ -137,6 +137,10 @@ typing._TypedDict.pop
137137
typing._TypedDict.setdefault
138138
typing._TypedDict.update
139139
typing._TypedDict.values
140+
typing_extensions\.Final
141+
typing\.NamedTuple
142+
typing\.LiteralString
143+
typing\.Annotated
140144

141145
# White lies around defaults
142146
dataclasses.KW_ONLY

tests/stubtest_allowlists/py37.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ types.GetSetDescriptorType.__get__
151151
types.MemberDescriptorType.__get__
152152
types.MethodDescriptorType.__get__
153153
types.WrapperDescriptorType.__get__
154+
155+
# https://github.com/python/mypy/issues/15302
156+
typing_extensions\.assert_never
157+
typing_extensions\.assert_type
158+
typing_extensions\.reveal_type
159+
160+
# Doesn't exist at runtime
161+
typing\.Protocol

tests/stubtest_allowlists/py38.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,11 @@ types.GetSetDescriptorType.__get__
169169
types.MemberDescriptorType.__get__
170170
types.MethodDescriptorType.__get__
171171
types.WrapperDescriptorType.__get__
172+
173+
# https://github.com/python/mypy/issues/15302
174+
typing_extensions\.assert_never
175+
typing_extensions\.assert_type
176+
typing_extensions\.reveal_type
177+
178+
# Super-special typing primitives
179+
typing_extensions\.Final

tests/stubtest_allowlists/py39.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,13 @@ types.GetSetDescriptorType.__get__
165165
types.MemberDescriptorType.__get__
166166
types.MethodDescriptorType.__get__
167167
types.WrapperDescriptorType.__get__
168+
169+
# https://github.com/python/mypy/issues/15302
170+
typing_extensions\.assert_never
171+
typing_extensions\.assert_type
172+
typing_extensions\.reveal_type
173+
174+
# Super-special typing primitives
175+
typing_extensions\.Final
176+
typing\.NamedTuple
177+
typing\.Annotated

tests/stubtest_allowlists/py3_common.txt

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,68 @@ pickle.Unpickler.memo # undocumented implementation detail, has different type
407407
re.Pattern.scanner # Undocumented and not useful. #6405
408408
tempfile._TemporaryFileWrapper.[\w_]+ # Dynamically specified by __getattr__, and thus don't exist on the class
409409

410-
# Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined.
411-
typing.[A-Z]\w+
412-
typing_extensions\..*
410+
# Details of runtime definition don't need to be in stubs
411+
typing_extensions\._SpecialForm.*
412+
typing_extensions\.TypeVar.*
413+
typing_extensions\.ParamSpec.*
414+
typing\.Generic
415+
typing\.Protocol
416+
417+
# Special primitives
418+
typing_extensions\.Annotated
419+
typing_extensions\.NamedTuple
420+
typing_extensions\.LiteralString
421+
typing_extensions\.Coroutine
422+
typing_extensions\.Awaitable
423+
typing_extensions\.AsyncIterator
424+
typing_extensions\.AsyncIterable
425+
typing_extensions\.AsyncGenerator
426+
typing\.ValuesView
427+
typing\.Sized
428+
typing\.Sequence
429+
typing\.Reversible
430+
typing\.Pattern
431+
typing\.MutableSet
432+
typing\.MutableSequence
433+
typing\.MutableMapping
434+
typing\.Match
435+
typing\.MappingView
436+
typing\.Mapping
437+
typing\.KeysView
438+
typing\.Iterator
439+
typing\.Iterable
440+
typing\.ItemsView
441+
typing\.Hashable
442+
typing\.Generator
443+
typing\.Coroutine
444+
typing\.Collection
445+
typing\.Container
446+
typing\.ByteString
447+
typing\.AwaitableGenerator
448+
typing\.Awaitable
449+
typing\.AsyncIterator
450+
typing\.AsyncIterable
451+
typing\.AsyncGenerator
452+
typing\.AbstractSet
453+
454+
# Internal attributes
455+
.*\.__protocol_attrs__
456+
.*\.__callable_proto_members_only__
457+
458+
# Exist at runtime for internal reasons, no need to put them in the stub
459+
typing_extensions\.TypeAliasType\.__call__
460+
typing_extensions\.TypeAliasType\.__init_subclass__
461+
462+
typing_extensions.NewType.__mro_entries__ # just exists for an error message
463+
464+
# We call them read-only properties, runtime implementation is slightly different
465+
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__
466+
467+
# https://github.com/python/mypy/issues/15302
468+
typing_extensions.NewType.__call__
469+
typing_extensions\.deprecated
470+
typing_extensions\.get_original_bases
471+
typing_extensions\.override
413472

414473
# These are abstract properties at runtime,
415474
# but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726)

0 commit comments

Comments
 (0)