1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
|
import abc
import sys
import typing
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction
from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager
from typing import ( # noqa: Y022,Y037,Y038,Y039
IO as IO,
TYPE_CHECKING as TYPE_CHECKING,
AbstractSet as AbstractSet,
Any as Any,
AnyStr as AnyStr,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
BinaryIO as BinaryIO,
Callable as Callable,
ChainMap as ChainMap,
ClassVar as ClassVar,
Collection as Collection,
Container as Container,
Coroutine as Coroutine,
Counter as Counter,
DefaultDict as DefaultDict,
Deque as Deque,
Dict as Dict,
ForwardRef as ForwardRef,
FrozenSet as FrozenSet,
Generator as Generator,
Generic as Generic,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Iterator as Iterator,
KeysView as KeysView,
List as List,
Mapping as Mapping,
MappingView as MappingView,
Match as Match,
MutableMapping as MutableMapping,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
NoReturn as NoReturn,
Optional as Optional,
Pattern as Pattern,
Reversible as Reversible,
Sequence as Sequence,
Set as Set,
Sized as Sized,
SupportsAbs as SupportsAbs,
SupportsBytes as SupportsBytes,
SupportsComplex as SupportsComplex,
SupportsFloat as SupportsFloat,
SupportsInt as SupportsInt,
SupportsRound as SupportsRound,
Text as Text,
TextIO as TextIO,
Tuple as Tuple,
Type as Type,
TypedDict as TypedDict,
Union as Union,
ValuesView as ValuesView,
_Alias,
cast as cast,
no_type_check as no_type_check,
no_type_check_decorator as no_type_check_decorator,
overload as overload,
type_check_only,
)
if sys.version_info >= (3, 10):
from types import UnionType
if sys.version_info >= (3, 9):
from types import GenericAlias
__all__ = [
"Any",
"Buffer",
"ClassVar",
"Concatenate",
"Final",
"LiteralString",
"ParamSpec",
"ParamSpecArgs",
"ParamSpecKwargs",
"Self",
"Type",
"TypeVar",
"TypeVarTuple",
"Unpack",
"Awaitable",
"AsyncIterator",
"AsyncIterable",
"Coroutine",
"AsyncGenerator",
"AsyncContextManager",
"CapsuleType",
"ChainMap",
"ContextManager",
"Counter",
"Deque",
"DefaultDict",
"NamedTuple",
"OrderedDict",
"TypedDict",
"SupportsIndex",
"SupportsAbs",
"SupportsRound",
"SupportsBytes",
"SupportsComplex",
"SupportsFloat",
"SupportsInt",
"Annotated",
"assert_never",
"assert_type",
"dataclass_transform",
"deprecated",
"final",
"IntVar",
"is_typeddict",
"Literal",
"NewType",
"overload",
"override",
"Protocol",
"reveal_type",
"runtime",
"runtime_checkable",
"Text",
"TypeAlias",
"TypeAliasType",
"TypeGuard",
"TYPE_CHECKING",
"Never",
"NoReturn",
"Required",
"NotRequired",
"clear_overloads",
"get_args",
"get_origin",
"get_original_bases",
"get_overloads",
"get_type_hints",
"AbstractSet",
"AnyStr",
"BinaryIO",
"Callable",
"Collection",
"Container",
"Dict",
"Doc",
"ForwardRef",
"FrozenSet",
"Generator",
"Generic",
"Hashable",
"IO",
"ItemsView",
"Iterable",
"Iterator",
"KeysView",
"List",
"Mapping",
"MappingView",
"Match",
"MutableMapping",
"MutableSequence",
"MutableSet",
"NoDefault",
"Optional",
"Pattern",
"Reversible",
"Sequence",
"Set",
"Sized",
"TextIO",
"Tuple",
"Union",
"ValuesView",
"cast",
"get_protocol_members",
"is_protocol",
"no_type_check",
"no_type_check_decorator",
"ReadOnly",
"TypeIs",
]
_T = typing.TypeVar("_T")
_F = typing.TypeVar("_F", bound=Callable[..., Any])
_TC = typing.TypeVar("_TC", bound=type[object])
class _Final: ... # This should be imported from typing but that breaks pytype
# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype
class _SpecialForm(_Final):
def __getitem__(self, parameters: Any) -> object: ...
if sys.version_info >= (3, 10):
def __or__(self, other: Any) -> _SpecialForm: ...
def __ror__(self, other: Any) -> _SpecialForm: ...
# Do not import (and re-export) Protocol or runtime_checkable from
# typing module because type checkers need to be able to distinguish
# typing.Protocol and typing_extensions.Protocol so they can properly
# warn users about potential runtime exceptions when using typing.Protocol
# on older versions of Python.
Protocol: _SpecialForm
def runtime_checkable(cls: _TC) -> _TC: ...
# This alias for above is kept here for backwards compatibility.
runtime = runtime_checkable
Final: _SpecialForm
def final(f: _F) -> _F: ...
Literal: _SpecialForm
def IntVar(name: str) -> Any: ... # returns a new TypeVar
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
# N.B. Keep this mostly in sync with typing._TypedDict/mypy_extensions._TypedDict
@type_check_only
class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
__required_keys__: ClassVar[frozenset[str]]
__optional_keys__: ClassVar[frozenset[str]]
__total__: ClassVar[bool]
__orig_bases__: ClassVar[tuple[Any, ...]]
# PEP 705
__readonly_keys__: ClassVar[frozenset[str]]
__mutable_keys__: ClassVar[frozenset[str]]
# PEP 728
__closed__: ClassVar[bool]
__extra_items__: ClassVar[Any]
def copy(self) -> Self: ...
# Using Never so that only calls using mypy plugin hook that specialize the signature
# can go through.
def setdefault(self, k: Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, m: _T, /) -> None: ...
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
def __delitem__(self, k: Never) -> None: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, value: Self, /) -> Self: ...
@overload
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
@overload
def __ror__(self, value: Self, /) -> Self: ...
@overload
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
# supposedly incompatible definitions of `__ior__` and `__or__`:
def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc]
OrderedDict = _Alias()
def get_type_hints(
obj: Callable[..., Any],
globalns: dict[str, Any] | None = None,
localns: Mapping[str, Any] | None = None,
include_extras: bool = False,
) -> dict[str, Any]: ...
def get_args(tp: Any) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 10):
@overload
def get_origin(tp: UnionType) -> type[UnionType]: ...
if sys.version_info >= (3, 9):
@overload
def get_origin(tp: GenericAlias) -> type: ...
@overload
def get_origin(tp: ParamSpecArgs | ParamSpecKwargs) -> ParamSpec: ...
@overload
def get_origin(tp: Any) -> Any | None: ...
Annotated: _SpecialForm
_AnnotatedAlias: Any # undocumented
@runtime_checkable
class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
@abc.abstractmethod
def __index__(self) -> int: ...
# New and changed things in 3.10
if sys.version_info >= (3, 10):
from typing import (
Concatenate as Concatenate,
ParamSpecArgs as ParamSpecArgs,
ParamSpecKwargs as ParamSpecKwargs,
TypeAlias as TypeAlias,
TypeGuard as TypeGuard,
is_typeddict as is_typeddict,
)
else:
@final
class ParamSpecArgs:
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...
@final
class ParamSpecKwargs:
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...
Concatenate: _SpecialForm
TypeAlias: _SpecialForm
TypeGuard: _SpecialForm
def is_typeddict(tp: object) -> bool: ...
# New and changed things in 3.11
if sys.version_info >= (3, 11):
from typing import (
LiteralString as LiteralString,
NamedTuple as NamedTuple,
Never as Never,
NewType as NewType,
NotRequired as NotRequired,
Required as Required,
Self as Self,
Unpack as Unpack,
assert_never as assert_never,
assert_type as assert_type,
clear_overloads as clear_overloads,
dataclass_transform as dataclass_transform,
get_overloads as get_overloads,
reveal_type as reveal_type,
)
else:
Self: _SpecialForm
Never: _SpecialForm
def reveal_type(obj: _T, /) -> _T: ...
def assert_never(arg: Never, /) -> Never: ...
def assert_type(val: _T, typ: Any, /) -> _T: ...
def clear_overloads() -> None: ...
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
Required: _SpecialForm
NotRequired: _SpecialForm
LiteralString: _SpecialForm
Unpack: _SpecialForm
def dataclass_transform(
*,
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
frozen_default: bool = False,
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = (),
**kwargs: object,
) -> IdentityFunction: ...
class NamedTuple(tuple[Any, ...]):
if sys.version_info < (3, 9):
_field_types: ClassVar[dict[str, type]]
_field_defaults: ClassVar[dict[str, Any]]
_fields: ClassVar[tuple[str, ...]]
__orig_bases__: ClassVar[tuple[Any, ...]]
@overload
def __init__(self, typename: str, fields: Iterable[tuple[str, Any]] = ...) -> None: ...
@overload
def __init__(self, typename: str, fields: None = None, **kwargs: Any) -> None: ...
@classmethod
def _make(cls, iterable: Iterable[Any]) -> Self: ...
def _asdict(self) -> dict[str, Any]: ...
def _replace(self, **kwargs: Any) -> Self: ...
class NewType:
def __init__(self, name: str, tp: Any) -> None: ...
def __call__(self, obj: _T, /) -> _T: ...
__supertype__: type | NewType
if sys.version_info >= (3, 10):
def __or__(self, other: Any) -> _SpecialForm: ...
def __ror__(self, other: Any) -> _SpecialForm: ...
if sys.version_info >= (3, 12):
from collections.abc import Buffer as Buffer
from types import get_original_bases as get_original_bases
from typing import TypeAliasType as TypeAliasType, override as override
else:
def override(arg: _F, /) -> _F: ...
def get_original_bases(cls: type, /) -> tuple[Any, ...]: ...
@final
class TypeAliasType:
def __init__(
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
) -> None: ...
@property
def __value__(self) -> Any: ...
@property
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
@property
def __parameters__(self) -> tuple[Any, ...]: ...
@property
def __name__(self) -> str: ...
# It's writable on types, but not on instances of TypeAliasType.
@property
def __module__(self) -> str | None: ... # type: ignore[override]
# Returns typing._GenericAlias, which isn't stubbed.
def __getitem__(self, parameters: Any) -> Any: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
# mypy and pyright object to this being both ABC and Protocol.
# At runtime it inherits from ABC and is not a Protocol, but it is on the
# allowlist for use as a Protocol.
@runtime_checkable
class Buffer(Protocol, abc.ABC): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
# Not actually a Protocol at runtime; see
# https://github.com/python/typeshed/issues/10224 for why we're defining it this way
def __buffer__(self, flags: int, /) -> memoryview: ...
if sys.version_info >= (3, 13):
from types import CapsuleType as CapsuleType
from typing import (
NoDefault as NoDefault,
ParamSpec as ParamSpec,
ReadOnly as ReadOnly,
TypeIs as TypeIs,
TypeVar as TypeVar,
TypeVarTuple as TypeVarTuple,
get_protocol_members as get_protocol_members,
is_protocol as is_protocol,
)
from warnings import deprecated as deprecated
else:
def is_protocol(tp: type, /) -> bool: ...
def get_protocol_members(tp: type, /) -> frozenset[str]: ...
@final
class _NoDefaultType: ...
NoDefault: _NoDefaultType
@final
class CapsuleType: ...
class deprecated:
message: LiteralString
category: type[Warning] | None
stacklevel: int
def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ...
def __call__(self, arg: _T, /) -> _T: ...
@final
class TypeVar:
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __constraints__(self) -> tuple[Any, ...]: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
@property
def __infer_variance__(self) -> bool: ...
@property
def __default__(self) -> Any: ...
def __init__(
self,
name: str,
*constraints: Any,
bound: Any | None = None,
covariant: bool = False,
contravariant: bool = False,
default: Any = ...,
infer_variance: bool = False,
) -> None: ...
def has_default(self) -> bool: ...
def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
if sys.version_info >= (3, 11):
def __typing_subst__(self, arg: Any) -> Any: ...
@final
class ParamSpec:
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
@property
def __infer_variance__(self) -> bool: ...
@property
def __default__(self) -> Any: ...
def __init__(
self,
name: str,
*,
bound: None | type[Any] | str = None,
contravariant: bool = False,
covariant: bool = False,
default: Any = ...,
) -> None: ...
@property
def args(self) -> ParamSpecArgs: ...
@property
def kwargs(self) -> ParamSpecKwargs: ...
def has_default(self) -> bool: ...
def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
@final
class TypeVarTuple:
@property
def __name__(self) -> str: ...
@property
def __default__(self) -> Any: ...
def __init__(self, name: str, *, default: Any = ...) -> None: ...
def __iter__(self) -> Any: ... # Unpack[Self]
def has_default(self) -> bool: ...
def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ...
ReadOnly: _SpecialForm
TypeIs: _SpecialForm
class Doc:
documentation: str
def __init__(self, documentation: str, /) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
|