Skip to content

Commit e4dcfcc

Browse files
Update typing-extensions; some 3.12 updates (#10200)
Co-authored-by: Alex Waygood <[email protected]>
1 parent e666602 commit e4dcfcc

File tree

6 files changed

+195
-33
lines changed

6 files changed

+195
-33
lines changed

stdlib/_collections_abc.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from abc import abstractmethod
23
from types import MappingProxyType
34
from typing import ( # noqa: Y022,Y038
45
AbstractSet as Set,
@@ -23,11 +24,13 @@ from typing import ( # noqa: Y022,Y038
2324
MutableMapping as MutableMapping,
2425
MutableSequence as MutableSequence,
2526
MutableSet as MutableSet,
27+
Protocol,
2628
Reversible as Reversible,
2729
Sequence as Sequence,
2830
Sized as Sized,
2931
TypeVar,
3032
ValuesView as ValuesView,
33+
runtime_checkable,
3134
)
3235
from typing_extensions import final
3336

@@ -58,6 +61,8 @@ __all__ = [
5861
"MutableSequence",
5962
"ByteString",
6063
]
64+
if sys.version_info >= (3, 12):
65+
__all__ += ["Buffer"]
6166

6267
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
6368
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
@@ -79,3 +84,9 @@ class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocum
7984
if sys.version_info >= (3, 10):
8085
@property
8186
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
87+
88+
if sys.version_info >= (3, 12):
89+
@runtime_checkable
90+
class Buffer(Protocol):
91+
@abstractmethod
92+
def __buffer__(self, __flags: int) -> memoryview: ...

stdlib/inspect.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,25 @@ def classify_class_attrs(cls: type) -> list[Attribute]: ...
598598

599599
if sys.version_info >= (3, 9):
600600
class ClassFoundException(Exception): ...
601+
602+
if sys.version_info >= (3, 12):
603+
class BufferFlags(enum.IntFlag):
604+
SIMPLE: int
605+
WRITABLE: int
606+
FORMAT: int
607+
ND: int
608+
STRIDES: int
609+
C_CONTIGUOUS: int
610+
F_CONTIGUOUS: int
611+
ANY_CONTIGUOUS: int
612+
INDIRECT: int
613+
CONTIG: int
614+
CONTIG_RO: int
615+
STRIDED: int
616+
STRIDED_RO: int
617+
RECORDS: int
618+
RECORDS_RO: int
619+
FULL: int
620+
FULL_RO: int
621+
READ: int
622+
WRITE: int

stdlib/typing.pyi

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,32 @@ Any = object()
136136

137137
@_final
138138
class TypeVar:
139-
__name__: str
140-
__bound__: Any | None
141-
__constraints__: tuple[Any, ...]
142-
__covariant__: bool
143-
__contravariant__: bool
144-
def __init__(
145-
self, name: str, *constraints: Any, bound: Any | None = None, covariant: bool = False, contravariant: bool = False
146-
) -> None: ...
139+
@property
140+
def __name__(self) -> str: ...
141+
@property
142+
def __bound__(self) -> Any | None: ...
143+
@property
144+
def __constraints__(self) -> tuple[Any, ...]: ...
145+
@property
146+
def __covariant__(self) -> bool: ...
147+
@property
148+
def __contravariant__(self) -> bool: ...
149+
if sys.version_info >= (3, 12):
150+
@property
151+
def __infer_variance__(self) -> bool: ...
152+
def __init__(
153+
self,
154+
name: str,
155+
*constraints: Any,
156+
bound: Any | None = None,
157+
covariant: bool = False,
158+
contravariant: bool = False,
159+
infer_variance: bool = False,
160+
) -> None: ...
161+
else:
162+
def __init__(
163+
self, name: str, *constraints: Any, bound: Any | None = None, covariant: bool = False, contravariant: bool = False
164+
) -> None: ...
147165
if sys.version_info >= (3, 10):
148166
def __or__(self, right: Any) -> _SpecialForm: ...
149167
def __ror__(self, left: Any) -> _SpecialForm: ...
@@ -194,29 +212,50 @@ if sys.version_info >= (3, 11):
194212
LiteralString: _SpecialForm
195213

196214
class TypeVarTuple:
197-
__name__: str
215+
@property
216+
def __name__(self) -> str: ...
198217
def __init__(self, name: str) -> None: ...
199218
def __iter__(self) -> Any: ...
200219
def __typing_subst__(self, arg: Never) -> Never: ...
201220
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...
202221

203222
if sys.version_info >= (3, 10):
204223
class ParamSpecArgs:
205-
__origin__: ParamSpec
224+
@property
225+
def __origin__(self) -> ParamSpec: ...
206226
def __init__(self, origin: ParamSpec) -> None: ...
207227

208228
class ParamSpecKwargs:
209-
__origin__: ParamSpec
229+
@property
230+
def __origin__(self) -> ParamSpec: ...
210231
def __init__(self, origin: ParamSpec) -> None: ...
211232

212233
class ParamSpec:
213-
__name__: str
214-
__bound__: Any | None
215-
__covariant__: bool
216-
__contravariant__: bool
217-
def __init__(
218-
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False
219-
) -> None: ...
234+
@property
235+
def __name__(self) -> str: ...
236+
@property
237+
def __bound__(self) -> Any | None: ...
238+
@property
239+
def __covariant__(self) -> bool: ...
240+
@property
241+
def __contravariant__(self) -> bool: ...
242+
if sys.version_info >= (3, 12):
243+
@property
244+
def __infer_variance__(self) -> bool: ...
245+
def __init__(
246+
self,
247+
name: str,
248+
*,
249+
bound: Any | None = None,
250+
contravariant: bool = False,
251+
covariant: bool = False,
252+
infer_variance: bool = False,
253+
) -> None: ...
254+
else:
255+
def __init__(
256+
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False
257+
) -> None: ...
258+
220259
@property
221260
def args(self) -> ParamSpecArgs: ...
222261
@property
@@ -873,3 +912,26 @@ if sys.version_info >= (3, 10):
873912
def is_typeddict(tp: object) -> bool: ...
874913

875914
def _type_repr(obj: object) -> str: ...
915+
916+
if sys.version_info >= (3, 12):
917+
def override(__arg: _F) -> _F: ...
918+
@_final
919+
class TypeAliasType:
920+
def __init__(
921+
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
922+
) -> None: ...
923+
@property
924+
def __value__(self) -> Any: ...
925+
@property
926+
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
927+
@property
928+
def __parameters__(self) -> tuple[Any, ...]: ...
929+
@property
930+
def __name__(self) -> str: ...
931+
# It's writable on types, but not on instances of TypeAliasType.
932+
@property
933+
def __module__(self) -> str | None: ... # type: ignore[override]
934+
def __getitem__(self, parameters: Any) -> Any: ...
935+
if sys.version_info >= (3, 10):
936+
def __or__(self, right: Any) -> _SpecialForm: ...
937+
def __ror__(self, left: Any) -> _SpecialForm: ...

stdlib/typing_extensions.pyi

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ from typing import ( # noqa: Y022,Y039
2525
NewType as NewType,
2626
NoReturn as NoReturn,
2727
Sequence,
28+
SupportsAbs as SupportsAbs,
29+
SupportsBytes as SupportsBytes,
30+
SupportsComplex as SupportsComplex,
31+
SupportsFloat as SupportsFloat,
32+
SupportsInt as SupportsInt,
33+
SupportsRound as SupportsRound,
2834
Text as Text,
2935
Type as Type,
3036
_Alias,
@@ -39,6 +45,7 @@ if sys.version_info >= (3, 9):
3945

4046
__all__ = [
4147
"Any",
48+
"Buffer",
4249
"ClassVar",
4350
"Concatenate",
4451
"Final",
@@ -66,6 +73,12 @@ __all__ = [
6673
"OrderedDict",
6774
"TypedDict",
6875
"SupportsIndex",
76+
"SupportsAbs",
77+
"SupportsRound",
78+
"SupportsBytes",
79+
"SupportsComplex",
80+
"SupportsFloat",
81+
"SupportsInt",
6982
"Annotated",
7083
"assert_never",
7184
"assert_type",
@@ -272,16 +285,24 @@ else:
272285

273286
# New things in 3.xx
274287
# The `default` parameter was added to TypeVar, ParamSpec, and TypeVarTuple (PEP 696)
275-
# The `infer_variance` parameter was added to TypeVar (PEP 695)
288+
# The `infer_variance` parameter was added to TypeVar in 3.12 (PEP 695)
276289
# typing_extensions.override (PEP 698)
277290
@final
278291
class TypeVar:
279-
__name__: str
280-
__bound__: Any | None
281-
__constraints__: tuple[Any, ...]
282-
__covariant__: bool
283-
__contravariant__: bool
284-
__default__: Any | None
292+
@property
293+
def __name__(self) -> str: ...
294+
@property
295+
def __bound__(self) -> Any | None: ...
296+
@property
297+
def __constraints__(self) -> tuple[Any, ...]: ...
298+
@property
299+
def __covariant__(self) -> bool: ...
300+
@property
301+
def __contravariant__(self) -> bool: ...
302+
@property
303+
def __infer_variance__(self) -> bool: ...
304+
@property
305+
def __default__(self) -> Any | None: ...
285306
def __init__(
286307
self,
287308
name: str,
@@ -300,11 +321,18 @@ class TypeVar:
300321

301322
@final
302323
class ParamSpec:
303-
__name__: str
304-
__bound__: type[Any] | None
305-
__covariant__: bool
306-
__contravariant__: bool
307-
__default__: type[Any] | None
324+
@property
325+
def __name__(self) -> str: ...
326+
@property
327+
def __bound__(self) -> Any | None: ...
328+
@property
329+
def __covariant__(self) -> bool: ...
330+
@property
331+
def __contravariant__(self) -> bool: ...
332+
@property
333+
def __infer_variance__(self) -> bool: ...
334+
@property
335+
def __default__(self) -> Any | None: ...
308336
def __init__(
309337
self,
310338
name: str,
@@ -321,10 +349,41 @@ class ParamSpec:
321349

322350
@final
323351
class TypeVarTuple:
324-
__name__: str
325-
__default__: Any | None
352+
@property
353+
def __name__(self) -> str: ...
354+
@property
355+
def __default__(self) -> Any | None: ...
326356
def __init__(self, name: str, *, default: Any | None = None) -> None: ...
327357
def __iter__(self) -> Any: ... # Unpack[Self]
328358

329-
def override(__arg: _F) -> _F: ...
330359
def deprecated(__msg: str, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> Callable[[_T], _T]: ...
360+
361+
if sys.version_info >= (3, 12):
362+
from collections.abc import Buffer as Buffer
363+
from types import get_original_bases as get_original_bases
364+
from typing import TypeAliasType as TypeAliasType, override as override
365+
else:
366+
def override(__arg: _F) -> _F: ...
367+
def get_original_bases(__cls: type) -> tuple[Any, ...]: ...
368+
@final
369+
class TypeAliasType:
370+
def __init__(
371+
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
372+
) -> None: ...
373+
@property
374+
def __value__(self) -> Any: ...
375+
@property
376+
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
377+
@property
378+
def __parameters__(self) -> tuple[Any, ...]: ...
379+
@property
380+
def __name__(self) -> str: ...
381+
# It's writable on types, but not on instances of TypeAliasType.
382+
@property
383+
def __module__(self) -> str | None: ... # type: ignore[override]
384+
def __getitem__(self, parameters: Any) -> Any: ...
385+
if sys.version_info >= (3, 10):
386+
def __or__(self, right: Any) -> _SpecialForm: ...
387+
def __ror__(self, left: Any) -> _SpecialForm: ...
388+
389+
class Buffer(abc.ABC): ...

tests/stubtest_allowlists/py310.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,6 @@ ast.ImportFrom.level # None on the class, but never None on instances
169169

170170
# White lies around defaults
171171
dataclasses.KW_ONLY
172+
173+
# We pretend it's a read-only property for forward compatibility with 3.12
174+
typing.ParamSpec(Args|Kwargs).__origin__

tests/stubtest_allowlists/py311.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,8 @@ typing._TypedDict.values
140140

141141
# White lies around defaults
142142
dataclasses.KW_ONLY
143+
144+
# We pretend it's a read-only property for forward compatibility with 3.12
145+
typing.ParamSpec(Args|Kwargs).__origin__
146+
typing\.TypeVar\.__.*__
147+
typing\.ParamSpec\.__.*__

0 commit comments

Comments
 (0)