Repository URL to install this package:
|
Version:
2022.2.8 ▾
|
# Special-cased by the parser: TypeVar, Any, NamedTuple, Optional, Union
__all__ = ... # type: List[str]
if sys.version_info >= (3, 0):
AnyStr = TypeVar('AnyStr', str, bytes)
else:
AnyStr = TypeVar('AnyStr', str, unicode)
_ARGS = TypeVar('_ARGS')
_RET = TypeVar('_RET')
# "_T", "_K", and "_V" are hardcoded in abstract.py
_T = TypeVar('_T')
_K = TypeVar('_K')
_V = TypeVar('_V')
_K2 = TypeVar('_K2')
_V2 = TypeVar('_V2')
_T2 = TypeVar('_T2')
_T_IO = TypeVar('_T_IO', bound=IO)
# Used by ChainMap to approximate a variadic type variable.
_K1 = TypeVar('_K1')
_K3 = TypeVar('_K3')
_K4 = TypeVar('_K4')
_V1 = TypeVar('_V1')
_V3 = TypeVar('_V3')
_V4 = TypeVar('_V4')
if sys.version_info >= (3, 0):
Text = str
else:
Text = Union[str, unicode]
# This function does not exist in typing.py. It is here for documentation
# purposes and to make it easier for pytype to type-check arguments to TypeVar.
def _typevar_new(name: Text, *constraints: Union[type, Text], bound: Union[type, Text]=None, covariant: bool=False, contravariant: bool=False): ...
class Callable(Generic[_ARGS, _RET], Protocol):
if sys.version_info < (3, 0):
func_name: str
else:
__annotations__: Dict[str, Any]
__kwdefaults__: Dict[str, Any]
__qualname__: str
__closure__: Optional[Tuple[Any, ...]]
__code__: Any
__defaults__: Optional[Tuple[Any, ...]]
__globals__: Dict[str, Any]
# Copied from types.FunctionType.__init__ with some types changed to Any.
def __init__(self, code: Any, globals: Dict[str, Any], name: Optional[str] = ..., argdefs: Optional[Tuple[object, ...]] = ..., closure: Optional[Tuple[Any, ...]] = ...) -> None:
self = Callable[..., Any]
@abstractmethod
def __call__(self, *args, **kwargs) -> _RET: ...
class Generic(object):
__slots__ = []
if sys.version_info < (3, 7):
class GenericMeta(type): ...
# This class is the implementation of PEP 586
# (https://www.python.org/dev/peps/pep-0586/)
class Literal(Generic[_T]):
__slots__ = []
# This class is the implementation of PEP 544
# (https://www.python.org/dev/peps/pep-0544/)
class Protocol(object):
__slots__ = []
class SupportsInt(Protocol):
__slots__ = []
@abstractmethod
def __int__(self) -> int: ...
class SupportsFloat(Protocol):
__slots__ = []
@abstractmethod
def __float__(self) -> float: ...
class SupportsComplex(Protocol):
__slots__ = []
@abstractmethod
def __complex__(self) -> complex: ...
class SupportsAbs(Generic[_T], Protocol):
__slots__ = []
@abstractmethod
def __abs__(self) -> _T: ...
class SupportsRound(Generic[_T], Protocol):
__slots__ = []
@abstractmethod
def __round__(self, ndigits: int = ...) -> _T: ...
# The SupportsBytes protocol was introduced in python3 typeshed.
if sys.version_info >= (3, 0):
class SupportsBytes(Protocol):
__slots__ = []
@abstractmethod
def __bytes__(self) -> bytes: ...
if sys.version_info >= (3, 8):
class SupportsIndex(Protocol):
__slots__ = []
@abstractmethod
def __index__(self) -> int: ...
class Reversible(Generic[_T], Protocol):
__slots__ = []
@abstractmethod
def __reversed__(self) -> Iterator[_T]: ...
class Iterator(Iterable[_T], Protocol):
__slots__ = []
if sys.version_info >= (3, 0):
@abstractmethod
def __next__(self) -> _T: ...
else:
@abstractmethod
def next(self) -> _T: ...
class Iterable(Generic[_T], Protocol):
__slots__ = []
@abstractmethod
def __iter__(self) -> Iterator[_T]: ...
class Sized(Protocol):
__slots__ = []
@abstractmethod
def __len__(self) -> int: ...
class Hashable(Protocol):
__slots__ = []
@abstractmethod
def __hash__(self) -> int: ...
class Container(Generic[_T], Protocol):
__slots__ = []
@abstractmethod
def __contains__(self, x) -> bool: ...
class Sequence(Sized, Iterable[_T], Container[_T], Reversible[_T], Protocol):
__slots__ = []
@abstractmethod
def __getitem__(self, i: int) -> _T: ...
@abstractmethod
def __getitem__(self, s: slice) -> Sequence[_T]: ...
def __getslice__(self, *args, **kwargs) -> Sequence[_T]: ...
def index(self, x) -> int: ...
def count(self, x) -> int: ...
def __contains__(self, x) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __reversed__(self) -> Iterator[_T]: ...
class Collection(Sized, Iterable[_T], Container[_T], Protocol):
__slots__ = []
class Tuple(Sequence[_T]):
__slots__ = []
def __len__(self) -> int: ...
class MutableSequence(Sequence[_T], Protocol):
__slots__ = []
@abstractmethod
def __setitem__(self, i: int, v: _T2) -> None:
self = MutableSequence[Union[_T, _T2]]
@abstractmethod
def __setitem__(self, i: slice, v: Iterable[_T2]) -> None:
self = MutableSequence[Union[_T, _T2]]
if sys.version_info < (3, 0):
def __setslice__(self, i: int, j: int, s: Iterable[_T2]) -> None:
self = MutableSequence[Union[_T, _T2]]
@abstractmethod
def __delitem__(self, i: Union[int, slice]) -> None: ...
def __add__(self, x: Iterable[_T2]) -> MutableSequence[Union[_T, _T2]]: ...
def append(self, v: _T2) -> None:
self = MutableSequence[Union[_T, _T2]]
def extend(self, iterable: Iterable[_T2]) -> None:
self = MutableSequence[Union[_T, _T2]]
@abstractmethod
def insert(self, i: int, v: _T2) -> None:
self = MutableSequence[Union[_T, _T2]]
def reverse(self) -> None: ...
def pop(self, index: int = ...) -> _T: ...
def remove(self, value: _T) -> None: ...
class List(MutableSequence[_T]):
__slots__ = []
__hash__ = ... # type: None
def __len__(self) -> int: ...
# typing.Deque subclasses collections.deque and MutableSequence[_T], but there's
# no actual way to represent that without introducing an import cycle.
class Deque(MutableSequence[_T]):
maxlen = ... # type: Optional[int]
def __init__(self, iterable: Iterable[_T] = ..., maxlen: Optional[int] = ...) -> None:
self = Deque[_T]
def appendleft(self, v: _T2) -> None:
self = Deque[Union[_T, _T2]]
def clear(self) -> None:
self = Deque[nothing]
def copy(self) -> Deque[_T]: ...
def extendleft(self, iterable: Iterable[_T2]) -> None:
self = Deque[Union[_T, _T2]]
def popleft(self, index: int = ...) -> _T: ...
def rotate(self, steps: int = ...) -> None: ...
class IO(Iterator[AnyStr]):
name = ... # type: str
mode = ... # type: str
closed = ... # type: bool
newlines = ... # type: Union[None, str, Tuple[str,...]]
def __enter__(self: _T_IO) -> _T_IO: ...
def __exit__(self, t, value, traceback) -> bool: ...
def __iter__(self) -> Iterator[AnyStr]: ...
if sys.version_info >= (3, 0):
def __next__(self) -> AnyStr: ...
else:
def next(self) -> AnyStr: ...
def close(self) -> None: ...
def fileno(self) -> int: ...
def flush(self) -> None: ...
def isatty(self) -> bool: ...
def read(self, n: int = ...) -> AnyStr: ...
def readable(self) -> bool: ...
def readline(self, limit: int = ...) -> AnyStr: ...
def readlines(self, hint: int = ...) -> list[AnyStr]: ...
def seek(self, offset: int, whence: int = ...) -> None: ...
def seekable(self) -> bool: ...
def tell(self) -> int: ...
def truncate(self, size: int = ...) -> Optional[int]: ...
def writable(self) -> bool: ...
if sys.version_info >= (3, 0):
def write(self, s: AnyStr) -> int: ...
else:
def write(self, s: Union[bytes, bytearray, Text]) -> int: ...
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
class BinaryIO(IO[bytes]): ...
if sys.version_info >= (3, 0):
class TextIO(IO[str]):
buffer: BinaryIO
else:
class TextIO(IO[unicode]): ...
class Mapping(Sized, Iterable[_K], Container[_K], Generic[_K, _V], Protocol):
__slots__ = []
def copy(self) -> Mapping[_K, _V]: ...
def __contains__(self, o) -> bool: ...
@abstractmethod
def __getitem__(self, key: _K) -> _V: ...
def get(self, k) -> Union[_V, NoneType]: ...
def get(self, k, d: _V2) -> Union[_V, _V2]: ...
# TODO(b/159065169): The below should be "AbstractSet", not "list"
def items(self) -> list[Tuple[_K, _V]]: ...
def keys(self) -> list[_K]: ...
def values(self) -> list[_V]: ...
if sys.version_info < (3, 0):
def iteritems(self) -> Iterator[Tuple[_K, _V]]: ...
def iterkeys(self) -> Iterator[_K]: ...
def itervalues(self) -> Iterator[_V]: ...
def viewitems(self) -> ItemsView[_K, _V]: ...
def viewkeys(self) -> KeysView[_K]: ...
def viewvalues(self) -> ValuesView[_V]: ...
class MutableMapping(Mapping[_K, _V], Protocol):
__slots__ = []
def copy(self) -> MutableMapping[_K, _V]: ...
@abstractmethod
def __setitem__(self, k: _K2, v: _V2) -> None:
self = MutableMapping[Union[_K, _K2], Union[_V, _V2]]
@abstractmethod
def __delitem__(self, k) -> None: ...
def clear(self) -> None:
self = MutableMapping[nothing, nothing]
def pop(self, k, default: _V2 = ...) -> Union[_V, _V2]: ...
def popitem(self) -> Tuple[_K, _V]: ...
def setdefault(self, k: _K2, default: _V2 = ...) -> Union[_V, _V2]:
self = MutableMapping[Union[_K, _K2], Union[_V, _V2]]
def update(self, m: Mapping[_K2, _V2]) -> None:
self = MutableMapping[Union[_K, _K2], Union[_V, _V2]]
def update(self, m: Iterable[Tuple[_T, ...]]) -> None:
self = MutableMapping[Union[_K, _T], Union[_V, _T]]
class Dict(MutableMapping[_K, _V]):
__slots__ = []
def __getitem__(self, key: _K) -> _V: ...
def __len__(self) -> int: ...
class DefaultDict(Dict[_K, _V]): ...
if sys.version_info >= (3, 7):
class OrderedDict(Dict[_K, _V]): ...
class AbstractSet(Sized, Iterable[_T], Container[_T]):
__slots__ = []
def __contains__(self, x) -> bool: ...
def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T]: ...
def __or__(self, s: AbstractSet[_T2]) -> AbstractSet[Union[_T, _T2]]: ...
def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T]: ...
def __xor__(self, s: AbstractSet[_T2]) -> AbstractSet[Union[_T, _T2]]: ...
def isdisjoint(self, s: Iterable) -> bool: ...
class FrozenSet(AbstractSet[_T]):
__slots__ = []
def __len__(self) -> int: ...
class MutableSet(AbstractSet[_T]):
__slots__ = []
def add(self, x: _T2) -> None:
self = MutableSet[Union[_T, _T2]]
def discard(self, x) -> None: ...
def clear(self) -> None:
self = MutableSet[nothing]
def pop(self) -> _T: ...
def remove(self, element: _T) -> None: ...
def __or__(self, s: AbstractSet[_T2]) -> MutableSet[Union[_T, _T2]]: ...
def __and__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
def __xor__(self, s: AbstractSet[_T2]) -> MutableSet[Union[_T, _T2]]: ...
def __sub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
class Set(MutableSet[_T]):
__slots__ = []
def __len__(self) -> int: ...
# _T is the yield type, _T2 the send type, _V the return type.
class Generator(Iterator[_T], Generic[_T, _T2, _V]):
__slots__ = []
gi_code: Any # Should be types.CodeType
gi_frame: Any # Should be types.FrameType
gi_running: bool
gi_yieldfrom: Optional[Generator[Any, Any, Any]]
if sys.version_info >= (3, 0):
def __next__(self) -> _T: ...
else:
def next(self) -> _T: ...
def send(self, value: _T2) -> _T: ...
def throw(self, typ: BaseException, val = ..., tb = ...) -> _T: ...
def close(self) -> None: ...
class Type(Generic[_T]): ...
class Pattern(Generic[AnyStr]):
flags = ... # type: int
groups = ... # type: int
groupindex = ... # type: Dict[str, int]
pattern = ... # type: AnyStr
# TODO(rechen): search() and match() can both return None.
def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr]: ...
def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr]: ...
def fullmatch(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Optional[Match[AnyStr]]: ...
def split(self, string: AnyStr, maxsplit: int = ...) -> List[AnyStr]: ...
def findall(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> List[Any]: ...
def finditer(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Iterator[Match[AnyStr]]: ...
def sub(self, repl: Union[AnyStr, Callable], string: AnyStr, count: int = ...) -> AnyStr: ...
def subn(self, repl: Union[AnyStr, Callable], string: AnyStr, count: int = ...) -> Tuple[AnyStr, int]: ...
class Match(Generic[AnyStr]):
pos = ... # type: int
endpos = ... # type: int
lastindex = ... # type: int
lastgroup = ... # type: Union[str, None]
re = ... # type: Pattern[AnyStr]
string = ... # type: AnyStr
def expand(self, template: AnyStr) -> AnyStr: ...
def group(self) -> AnyStr: ...
def group(self, group1: Union[Text, int]) -> AnyStr: ...
def group(self, group1: Union[Text, int], group2: Union[Text, int], *groups) -> Tuple[AnyStr, ...]: ...
@overload
def groups(self) -> Tuple[Optional[AnyStr], ...]: ...
@overload
def groups(self, default: _T = ...) -> Tuple[Union[AnyStr, _T], ...]: ...
def groupdict(self, default: AnyStr = ...) -> Dict[str, AnyStr]: ...
def start(self, group: Union[int, Text] = ...) -> int: ...
def end(self, group: Union[int, Text] = ...) -> int: ...
def span(self, group: Union[int, Text] = ...) -> Tuple[int, int]: ...
if sys.version_info >= (3, 6):
def __getitem__(self, g: Union[Text, int]) -> AnyStr: ...
# Used to mark attributes as class-level, as opposed to instance-level.
class ClassVar(Generic[_T]): ...
ByteString = Union[bytes, bytearray, memoryview]
# TODO(tsudol): Should be covariant, e.g. _T_co. traceback arg for __exit__
# should be types.TracebackType.
class ContextManager(Generic[_T], Protocol):
@abstractmethod
def __enter__(self) -> _T: ...
@abstractmethod
def __exit__(self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[Any]) -> Optional[bool]: ...
class MappingView(Sized, Iterable[_T]):
__slots__ = []
class KeysView(MappingView[_T], AbstractSet[_T]):
def __init__(self, mapping: Mapping[_T, _V]) -> None: ...
def __contains__(self, o: object) -> bool: ...
__slots__ = []
class ValuesView(MappingView[_T]):
def __init__(self, mapping: Mapping[_K, _T]) -> None: ...
def __contains__(self, o: object) -> bool: ...
__slots__ = []
class ItemsView(MappingView[Tuple[_K, _V]], AbstractSet[Tuple[_K, _V]]):
def __init__(self, mapping: Mapping[_K, _V]) -> None: ...
def __contains__(self, o: object) -> bool: ...
__slots__ = []
NoReturn = nothing
def _NamedTuple(typename: Text, fields: Sequence[Sequence[Union[Text, type]]]) -> Any: ...
# A more precise (but incorrect) fields type for error messages.
_NamedTupleFields = List[Tuple[Text, type]]
if sys.version_info >= (3, 6):
class _NamedTupleClass(object):
__slots__ = []
def NewType(name: str, tp: type) -> type: ...
def cast(typ: Type[_T], val) -> _T: ...
def overload(func: _T) -> _T: ...
def no_type_check(arg: _T) -> _T: ...
def no_type_check_decorator(decorator) -> Callable: ...
def get_type_hints(obj, *args, **kwargs) -> Optional[Dict[str, Any]]: ...
# This function is new in Python 3.8, but we define it unconditionally for
# compatibility with typeshed, which does the same.
def runtime_checkable(cls: _T) -> _T: ...
if sys.version_info >= (3, 8):
def get_origin(tp: Any) -> Optional[Any]: ...
def get_args(tp: Any) -> Tuple[Any, ...]: ...
# Strictly speaking, this should be Dict[_K, _V]. (E.g. it's legal to do
# typing.Counter()[x] = 'foobar'.) But the counts are typically integers.
class Counter(Dict[_K, int]):
__doc__ = ... # type: str
fromkeys = ... # type: classmethod
def __add__(self, other: Counter[_K2]) -> Counter[Union[_K, _K2]]: ...
def __and__(self, other: Counter[_K]) -> Counter[_K]: ...
def __delitem__(self, elem) -> None: ...
def __init__(self, *args, **kwargs) -> None: ...
def __missing__(self, key) -> int: ...
def __or__(self, other: Counter[_K2]) -> Counter[Union[_K, _K2]]: ...
def __reduce__(self) -> Tuple: ...
def __repr__(self) -> str: ...
def __sub__(self, other: Counter[_K]) -> Counter[_K]: ...
def copy(self) -> Counter[_K]: ...
def elements(self) -> Iterable[_K]: ...
def most_common(self, n: Optional[int] = ...) -> List[Tuple[_K, int]]: ...
def subtract(self, other: Iterable) -> None: ...
def update(self, other: Iterable) -> None: ...
if sys.version_info >= (3, 0):
class AsyncIterable(Generic[_T], Protocol):
__slots__ = []
if sys.version_info < (3, 5):
@abstractmethod
def __aiter__(self) -> Awaitable[AsyncIterator[_T]]: ...
else:
@abstractmethod
def __aiter__(self) -> AsyncIterator[_T]: ...
class AsyncIterator(AsyncIterable[_T], Protocol):
__slots__ = []
@abstractmethod
def __anext__(self) -> Awaitable[_T]: ...
class ChainMap(MutableMapping[_K, _V]):
maps: List[Mapping[_K, _V]]
parents: ChainMap[_K, _V]
def __init__(self) -> None:
self = ChainMap[nothing, nothing]
def __init__(self, map1: Mapping[_K1, _V1]) -> None:
self = ChainMap[_K1, _V1]
def __init__(
self,
map1: Mapping[_K1, _V1],
map2: Mapping[_K2, _V2]
) -> None:
self = ChainMap[Union[_K1, _K2], Union[_V1, _V2]]
def __init__(
self,
map1: Mapping[_K1, _V1],
map2: Mapping[_K2, _V2],
map3: Mapping[_K3, _V3]
) -> None:
self = ChainMap[Union[_K1, _K2, _K3], Union[_V1, _V2, _V3]]
def __init__(
self,
map1: Mapping[_K1, _V1],
map2: Mapping[_K2, _V2],
map3: Mapping[_K3, _V3],
map4: Mapping[_K4, _V4]
) -> None:
self = ChainMap[Union[_K1, _K2, _K3, _K4], Union[_V1, _V2, _V3, _V4]]
def __init__(self, *maps: Mapping[Any, Any]) -> None:
self = ChainMap[Any, Any]
def __delitem__(self, k) -> None: ...
def __getitem__(self, key: _K) -> _V: ...
def __iter__(self) -> Iterator[_K]: ...
def __len__(self) -> int: ...
def __setitem__(self, k: _K2, v: _V2) -> None:
self = ChainMap[Union[_K, _K2], Union[_V, _V2]]
def new_child(self, m: None = ...) -> ChainMap[_K, _V]: ...
def new_child(
self, m: Mapping[_K2, _V2]
) -> ChainMap[Union[_K, _K2], Union[_V2, _V2]]: ...
if sys.version_info >= (3, 5):
class Awaitable(Generic[_T], Protocol):
@abstractmethod
def __await__(self) -> Generator[Any, None, _T]: ...
class Coroutine(Awaitable[_V], Generic[_T, _T2, _V]):
__slots__ = []
@abstractmethod
def send(self, value: _T2) -> _T: ...
@abstractmethod
def throw(self, typ: Type[BaseException], val = ..., tb = ...) -> _T: ...
@abstractmethod
def close(self) -> None: ...
if sys.version_info >= (3, 5):
class AsyncContextManager(Generic[_T], Protocol):
@abstractmethod
def __aenter__(self) -> Awaitable[_T]: ...
@abstractmethod
def __aexit__(self, exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[Any]) -> Awaitable[Optional[bool]]: ...
if sys.version_info >= (3, 6):
# _T is the yield type, _T2 the send type
class AsyncGenerator(AsyncIterator[_T], Generic[_T, _T2]):
__slots__ = []
@abstractmethod
def asend(self, value: _T2) -> Awaitable[_T]: ...
@abstractmethod
def athrow(self, typ: Type[BaseException], val = ..., tb = ...) -> Awaitable[_T]: ...
@abstractmethod
def aclose(self) -> Awaitable[_T]: ...
# Internal pytd class for typed dicts, used as the pyval for
# typing_extensions.TypedDict before 3.8 and typing.TypedDict thereafter.
class _TypedDict(Mapping[str, object]): ...
# The following types are new in Python 3.8 or 3.9; we don't put a version
# guard here because we want to reuse the definitions for typing_extensions in
# lower versions.
# if sys.version_info >= (3, 8):
def final(x: _T) -> _T: ...
# if sys.version_info >= (3, 8):
class Final(Generic[_T]): ...
# if sys.version_info >= (3, 8):
class TypedDict: ...
# if sys.version_info >= (3, 9):
class Annotated: ...
TYPE_CHECKING = ... # type: bool
# This does not exist at runtime; it needs to be here because it's used by
# typeshed (specifically, typing_extensions.pyi).
class _Alias:
def __getitem__(self, typeargs: Any) -> Any: ...