11import abc
2+ import enum
23import sys
34import typing
45from _collections_abc import dict_items , dict_keys , dict_values
5- from _typeshed import IdentityFunction
6+ from _typeshed import IdentityFunction , Incomplete , Unused
67from contextlib import AbstractAsyncContextManager as AsyncContextManager , AbstractContextManager as ContextManager
8+ from types import ModuleType
79from typing import ( # noqa: Y022,Y037,Y038,Y039
810 IO as IO ,
911 TYPE_CHECKING as TYPE_CHECKING ,
@@ -68,9 +70,10 @@ if sys.version_info >= (3, 10):
6870if sys .version_info >= (3 , 9 ):
6971 from types import GenericAlias
7072
73+ # Please keep order the same as at runtime.
7174__all__ = [
75+ # Super-special typing primitives.
7276 "Any" ,
73- "Buffer" ,
7477 "ClassVar" ,
7578 "Concatenate" ,
7679 "Final" ,
@@ -83,35 +86,51 @@ __all__ = [
8386 "TypeVar" ,
8487 "TypeVarTuple" ,
8588 "Unpack" ,
89+ # ABCs (from collections.abc).
8690 "Awaitable" ,
8791 "AsyncIterator" ,
8892 "AsyncIterable" ,
8993 "Coroutine" ,
9094 "AsyncGenerator" ,
9195 "AsyncContextManager" ,
92- "CapsuleType " ,
96+ "Buffer " ,
9397 "ChainMap" ,
98+ # Concrete collection types.
9499 "ContextManager" ,
95100 "Counter" ,
96101 "Deque" ,
97102 "DefaultDict" ,
98103 "NamedTuple" ,
99104 "OrderedDict" ,
100105 "TypedDict" ,
101- "SupportsIndex" ,
106+ # Structural checks, a.k.a. protocols.
102107 "SupportsAbs" ,
103- "SupportsRound" ,
104108 "SupportsBytes" ,
105109 "SupportsComplex" ,
106110 "SupportsFloat" ,
111+ "SupportsIndex" ,
107112 "SupportsInt" ,
113+ "SupportsRound" ,
114+ # One-off things.
108115 "Annotated" ,
109116 "assert_never" ,
110117 "assert_type" ,
118+ "clear_overloads" ,
111119 "dataclass_transform" ,
112120 "deprecated" ,
121+ "Doc" ,
122+ "evaluate_forward_ref" ,
123+ "get_overloads" ,
113124 "final" ,
125+ "Format" ,
126+ "get_annotations" ,
127+ "get_args" ,
128+ "get_origin" ,
129+ "get_original_bases" ,
130+ "get_protocol_members" ,
131+ "get_type_hints" ,
114132 "IntVar" ,
133+ "is_protocol" ,
115134 "is_typeddict" ,
116135 "Literal" ,
117136 "NewType" ,
@@ -124,26 +143,25 @@ __all__ = [
124143 "Text" ,
125144 "TypeAlias" ,
126145 "TypeAliasType" ,
146+ "TypeForm" ,
127147 "TypeGuard" ,
148+ "TypeIs" ,
128149 "TYPE_CHECKING" ,
129150 "Never" ,
130151 "NoReturn" ,
152+ "ReadOnly" ,
131153 "Required" ,
132154 "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
139158 "AbstractSet" ,
140159 "AnyStr" ,
141160 "BinaryIO" ,
142161 "Callable" ,
143162 "Collection" ,
144163 "Container" ,
145164 "Dict" ,
146- "Doc" ,
147165 "ForwardRef" ,
148166 "FrozenSet" ,
149167 "Generator" ,
@@ -161,7 +179,6 @@ __all__ = [
161179 "MutableMapping" ,
162180 "MutableSequence" ,
163181 "MutableSet" ,
164- "NoDefault" ,
165182 "Optional" ,
166183 "Pattern" ,
167184 "Reversible" ,
@@ -173,12 +190,10 @@ __all__ = [
173190 "Union" ,
174191 "ValuesView" ,
175192 "cast" ,
176- "get_protocol_members" ,
177- "is_protocol" ,
178193 "no_type_check" ,
179194 "no_type_check_decorator" ,
180- "ReadOnly" ,
181- "TypeIs " ,
195+ # Added dynamically
196+ "CapsuleType " ,
182197]
183198
184199_T = typing .TypeVar ("_T" )
@@ -382,33 +397,11 @@ if sys.version_info >= (3, 12):
382397 SupportsIndex as SupportsIndex ,
383398 SupportsInt as SupportsInt ,
384399 SupportsRound as SupportsRound ,
385- TypeAliasType as TypeAliasType ,
386400 override as override ,
387401 )
388402else :
389403 def override (arg : _F , / ) -> _F : ...
390404 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 : ...
412405
413406 # mypy and pyright object to this being both ABC and Protocol.
414407 # At runtime it inherits from ABC and is not a Protocol, but it is on the
@@ -569,8 +562,71 @@ else:
569562 ReadOnly : _SpecialForm
570563 TypeIs : _SpecialForm
571564
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
572595class Doc :
573596 documentation : str
574597 def __init__ (self , documentation : str , / ) -> None : ...
575598 def __hash__ (self ) -> int : ...
576599 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