1
1
import abc
2
+ import enum
2
3
import sys
3
4
import typing
4
5
from _collections_abc import dict_items , dict_keys , dict_values
5
- from _typeshed import IdentityFunction
6
+ from _typeshed import IdentityFunction , Incomplete , Unused
6
7
from contextlib import AbstractAsyncContextManager as AsyncContextManager , AbstractContextManager as ContextManager
8
+ from types import ModuleType
7
9
from typing import ( # noqa: Y022,Y037,Y038,Y039
8
10
IO as IO ,
9
11
TYPE_CHECKING as TYPE_CHECKING ,
@@ -68,9 +70,10 @@ if sys.version_info >= (3, 10):
68
70
if sys .version_info >= (3 , 9 ):
69
71
from types import GenericAlias
70
72
73
+ # Please keep order the same as at runtime.
71
74
__all__ = [
75
+ # Super-special typing primitives.
72
76
"Any" ,
73
- "Buffer" ,
74
77
"ClassVar" ,
75
78
"Concatenate" ,
76
79
"Final" ,
@@ -83,35 +86,51 @@ __all__ = [
83
86
"TypeVar" ,
84
87
"TypeVarTuple" ,
85
88
"Unpack" ,
89
+ # ABCs (from collections.abc).
86
90
"Awaitable" ,
87
91
"AsyncIterator" ,
88
92
"AsyncIterable" ,
89
93
"Coroutine" ,
90
94
"AsyncGenerator" ,
91
95
"AsyncContextManager" ,
92
- "CapsuleType " ,
96
+ "Buffer " ,
93
97
"ChainMap" ,
98
+ # Concrete collection types.
94
99
"ContextManager" ,
95
100
"Counter" ,
96
101
"Deque" ,
97
102
"DefaultDict" ,
98
103
"NamedTuple" ,
99
104
"OrderedDict" ,
100
105
"TypedDict" ,
101
- "SupportsIndex" ,
106
+ # Structural checks, a.k.a. protocols.
102
107
"SupportsAbs" ,
103
- "SupportsRound" ,
104
108
"SupportsBytes" ,
105
109
"SupportsComplex" ,
106
110
"SupportsFloat" ,
111
+ "SupportsIndex" ,
107
112
"SupportsInt" ,
113
+ "SupportsRound" ,
114
+ # One-off things.
108
115
"Annotated" ,
109
116
"assert_never" ,
110
117
"assert_type" ,
118
+ "clear_overloads" ,
111
119
"dataclass_transform" ,
112
120
"deprecated" ,
121
+ "Doc" ,
122
+ "evaluate_forward_ref" ,
123
+ "get_overloads" ,
113
124
"final" ,
125
+ "Format" ,
126
+ "get_annotations" ,
127
+ "get_args" ,
128
+ "get_origin" ,
129
+ "get_original_bases" ,
130
+ "get_protocol_members" ,
131
+ "get_type_hints" ,
114
132
"IntVar" ,
133
+ "is_protocol" ,
115
134
"is_typeddict" ,
116
135
"Literal" ,
117
136
"NewType" ,
@@ -124,26 +143,25 @@ __all__ = [
124
143
"Text" ,
125
144
"TypeAlias" ,
126
145
"TypeAliasType" ,
146
+ "TypeForm" ,
127
147
"TypeGuard" ,
148
+ "TypeIs" ,
128
149
"TYPE_CHECKING" ,
129
150
"Never" ,
130
151
"NoReturn" ,
152
+ "ReadOnly" ,
131
153
"Required" ,
132
154
"NotRequired" ,
133
- "clear_overloads" ,
134
- "get_args" ,
135
- "get_origin" ,
136
- "get_original_bases" ,
137
- "get_overloads" ,
138
- "get_type_hints" ,
155
+ "NoDefault" ,
156
+ "NoExtraItems" ,
157
+ # Pure aliases, have always been in typing
139
158
"AbstractSet" ,
140
159
"AnyStr" ,
141
160
"BinaryIO" ,
142
161
"Callable" ,
143
162
"Collection" ,
144
163
"Container" ,
145
164
"Dict" ,
146
- "Doc" ,
147
165
"ForwardRef" ,
148
166
"FrozenSet" ,
149
167
"Generator" ,
@@ -161,7 +179,6 @@ __all__ = [
161
179
"MutableMapping" ,
162
180
"MutableSequence" ,
163
181
"MutableSet" ,
164
- "NoDefault" ,
165
182
"Optional" ,
166
183
"Pattern" ,
167
184
"Reversible" ,
@@ -173,12 +190,10 @@ __all__ = [
173
190
"Union" ,
174
191
"ValuesView" ,
175
192
"cast" ,
176
- "get_protocol_members" ,
177
- "is_protocol" ,
178
193
"no_type_check" ,
179
194
"no_type_check_decorator" ,
180
- "ReadOnly" ,
181
- "TypeIs " ,
195
+ # Added dynamically
196
+ "CapsuleType " ,
182
197
]
183
198
184
199
_T = typing .TypeVar ("_T" )
@@ -382,33 +397,11 @@ if sys.version_info >= (3, 12):
382
397
SupportsIndex as SupportsIndex ,
383
398
SupportsInt as SupportsInt ,
384
399
SupportsRound as SupportsRound ,
385
- TypeAliasType as TypeAliasType ,
386
400
override as override ,
387
401
)
388
402
else :
389
403
def override (arg : _F , / ) -> _F : ...
390
404
def get_original_bases (cls : type , / ) -> tuple [Any , ...]: ...
391
- @final
392
- class TypeAliasType :
393
- def __init__ (
394
- self , name : str , value : Any , * , type_params : tuple [TypeVar | ParamSpec | TypeVarTuple , ...] = ()
395
- ) -> None : ...
396
- @property
397
- def __value__ (self ) -> Any : ...
398
- @property
399
- def __type_params__ (self ) -> tuple [TypeVar | ParamSpec | TypeVarTuple , ...]: ...
400
- @property
401
- def __parameters__ (self ) -> tuple [Any , ...]: ...
402
- @property
403
- def __name__ (self ) -> str : ...
404
- # It's writable on types, but not on instances of TypeAliasType.
405
- @property
406
- def __module__ (self ) -> str | None : ... # type: ignore[override]
407
- # Returns typing._GenericAlias, which isn't stubbed.
408
- def __getitem__ (self , parameters : Any ) -> Any : ...
409
- if sys .version_info >= (3 , 10 ):
410
- def __or__ (self , right : Any ) -> _SpecialForm : ...
411
- def __ror__ (self , left : Any ) -> _SpecialForm : ...
412
405
413
406
# mypy and pyright object to this being both ABC and Protocol.
414
407
# At runtime it inherits from ABC and is not a Protocol, but it is on the
@@ -569,8 +562,71 @@ else:
569
562
ReadOnly : _SpecialForm
570
563
TypeIs : _SpecialForm
571
564
565
+ # TypeAliasType was added in Python 3.12, but had significant changes in 3.14.
566
+ if sys .version_info >= (3 , 14 ):
567
+ from typing import TypeAliasType as TypeAliasType
568
+ else :
569
+ @final
570
+ class TypeAliasType :
571
+ def __init__ (
572
+ self , name : str , value : Any , * , type_params : tuple [TypeVar | ParamSpec | TypeVarTuple , ...] = ()
573
+ ) -> None : ... # value is a type expression
574
+ @property
575
+ def __value__ (self ) -> Any : ... # a type expression
576
+ @property
577
+ def __type_params__ (self ) -> tuple [TypeVar | ParamSpec | TypeVarTuple , ...]: ...
578
+ @property
579
+ # `__parameters__` can include special forms if a `TypeVarTuple` was
580
+ # passed as a `type_params` element to the constructor method.
581
+ def __parameters__ (self ) -> tuple [TypeVar | ParamSpec | Any , ...]: ...
582
+ @property
583
+ def __name__ (self ) -> str : ...
584
+ # It's writable on types, but not on instances of TypeAliasType.
585
+ @property
586
+ def __module__ (self ) -> str | None : ... # type: ignore[override]
587
+ # Returns typing._GenericAlias, which isn't stubbed.
588
+ def __getitem__ (self , parameters : Incomplete | tuple [Incomplete , ...]) -> Any : ...
589
+ def __init_subclass__ (cls , * args : Unused , ** kwargs : Unused ) -> NoReturn : ...
590
+ if sys .version_info >= (3 , 10 ):
591
+ def __or__ (self , right : Any ) -> _SpecialForm : ...
592
+ def __ror__ (self , left : Any ) -> _SpecialForm : ...
593
+
594
+ # PEP 727
572
595
class Doc :
573
596
documentation : str
574
597
def __init__ (self , documentation : str , / ) -> None : ...
575
598
def __hash__ (self ) -> int : ...
576
599
def __eq__ (self , other : object ) -> bool : ...
600
+
601
+ # PEP 728
602
+ class _NoExtraItemsType : ...
603
+
604
+ NoExtraItems : _NoExtraItemsType
605
+
606
+ # PEP 747
607
+ TypeForm : _SpecialForm
608
+
609
+ class Format (enum .IntEnum ):
610
+ VALUE = 1
611
+ FORWARDREF = 2
612
+ STRING = 3
613
+
614
+ # PEP 649/749
615
+ def get_annotations (
616
+ obj : Callable [..., object ] | type [object ] | ModuleType , # any callable, class, or module
617
+ * ,
618
+ globals : Mapping [str , Any ] | None = None , # value types depend on the key
619
+ locals : Mapping [str , Any ] | None = None , # value types depend on the key
620
+ eval_str : bool = False ,
621
+ format : Format = Format .VALUE , # noqa: Y011
622
+ ) -> dict [str , Any ]: ... # values are type expressions
623
+ def evaluate_forward_ref (
624
+ forward_ref : ForwardRef ,
625
+ * ,
626
+ owner : Callable [..., object ] | type [object ] | ModuleType | None = None , # any callable, class, or module
627
+ globals : Mapping [str , Any ] | None = None , # value types depend on the key
628
+ locals : Mapping [str , Any ] | None = None , # value types depend on the key
629
+ type_params : Iterable [TypeVar | ParamSpec | TypeVarTuple ] | None = None ,
630
+ format : Format = Format .VALUE , # noqa: Y011
631
+ _recursive_guard : Container [str ] = ...,
632
+ ) -> Any : ... # str if format is Format.STRING, otherwise a type expression
0 commit comments