Coding Python Base
Coding Python Base
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
Protocol,
import sys
else:
_T = TypeVar('_T')
_KT = TypeVar('_KT')
_VT = TypeVar('_VT')
_S = TypeVar('_S')
_T1 = TypeVar('_T1')
_T2 = TypeVar('_T2')
_T3 = TypeVar('_T3')
_T4 = TypeVar('_T4')
_T5 = TypeVar('_T5')
class _SupportsIndex(Protocol):
class object:
__doc__: Optional[str]
__module__: str
@property
@__class__.setter
__isabstractmethod__: bool
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ...
def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ...
__isabstractmethod__: bool
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ...
def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ...
class type(object):
__base__: type
__basicsize__: int
__dict__: Dict[str, Any]
__dictoffset__: int
__flags__: int
__itemsize__: int
__module__: str
__name__: str
__qualname__: str
__text_signature__: Optional[str]
__weakrefoffset__: int
@overload
@overload
def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ...
@overload
@overload
def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ...
# Note: the documentation doesnt specify what the return type is, the standard
@classmethod
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str,
Any]: ...
class super(object):
@overload
@overload
@overload
else:
@overload
@overload
class int:
@overload
def __init__(self, x: Union[Text, bytes, SupportsInt, _SupportsIndex] = ...) -> None: ...
@overload
def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ...
@property
@property
@property
@property
def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ...
@classmethod
signed: bool = ...) -> int: ... # TODO buffer object argument
def __pow__(self, __x: int, __modulo: Optional[int] = ...) -> Any: ... # Return type can be int or
float, depending on x.
else:
class float:
def __init__(self, x: Union[SupportsFloat, _SupportsIndex, Text, bytes, bytearray] = ...) -> None: ...
@classmethod
@property
@property
def __pow__(self, x: float) -> float: ... # In Python 3, returns complex if self is negative and x is not
whole
def __radd__(self, x: float) -> float: ...
@overload
@overload
else:
class complex:
@overload
def __init__(self, real: float = ..., imag: float = ...) -> None: ...
@overload
@property
@property
else:
_str_base = object
else:
@overload
@overload
@overload
def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ...
def center(self, width: int, fillchar: unicode = ...) -> unicode: ...
def count(self, x: unicode) -> int: ...
def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ...
def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ...
def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ...
def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ...
def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ...
def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ...
def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ...
def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ...
def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ...
def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ...
def rstrip(self, chars: unicode = ...) -> unicode: ...
def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ...
@overload
@overload
_str_base = basestring
@overload
@overload
def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ...
else:
def center(self, width: int, fillchar: str = ...) -> str: ...
def count(self, x: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
def decode(self, encoding: Text = ..., errors: Text = ...) -> unicode: ...
def encode(self, encoding: Text = ..., errors: Text = ...) -> bytes: ...
else:
def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ...
def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
else:
def ljust(self, width: int, fillchar: str = ...) -> str: ...
def replace(self, old: str, new: str, count: int = ...) -> str: ...
else:
@overload
@overload
@overload
@overload
@overload
def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ...
def rfind(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
def rindex(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
def rjust(self, width: int, fillchar: str = ...) -> str: ...
def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
else:
@overload
@overload
@overload
@overload
def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
@overload
def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ...
@overload
@overload
@overload
def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ...
@overload
def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ...
else:
@overload
@overload
else:
def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ...
@overload
def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ...
@staticmethod
@overload
def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ...
else:
class bytes(ByteString):
@overload
@overload
@overload
@overload
@overload
def center(self, width: int, fillchar: bytes = ...) -> bytes: ...
def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def decode(self, encoding: str = ..., errors: str = ...) -> str: ...
def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ...
def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ...
def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ...
def startswith(
self,
def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ...
@classmethod
@overload
@overload
else:
bytes = str
@overload
@overload
@overload
def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ...
@overload
else:
@overload
@overload
@overload
@overload
def __init__(self, string: Text, encoding: Text, errors: Text = ...) -> None: ...
@overload
def center(self, width: int, fillchar: bytes = ...) -> bytearray: ...
def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
else:
def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ...
def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ...
def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
else:
def find(self, sub: str, start: int = ..., end: int = ...) -> int: ...
def index(self, sub: str, start: int = ..., end: int = ...) -> int: ...
def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ...
else:
def ljust(self, width: int, fillchar: str = ...) -> bytearray: ...
def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ...
else:
def rfind(self, sub: bytes, start: int = ..., end: int = ...) -> int: ...
def rindex(self, sub: bytes, start: int = ..., end: int = ...) -> int: ...
def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ...
def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ...
def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ...
def startswith(
self,
def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ...
else:
@staticmethod
@overload
@overload
@overload
@overload
def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ...
_mv_container_type = int
else:
_mv_container_type = str
format: str
itemsize: int
readonly: bool
ndim: int
c_contiguous: bool
f_contiguous: bool
contiguous: bool
nbytes: int
else:
def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ...
@overload
@overload
@overload
@overload
@overload
class bool(int):
def __init__(self, o: object = ...) -> None: ...
@overload
@overload
@overload
@overload
@overload
@overload
@overload
@overload
@overload
@overload
@overload
@overload
class slice(object):
start: Any
step: Any
stop: Any
@overload
@overload
def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ...
@overload
@overload
@overload
@overload
def index(self, x: Any, start: int = ..., end: int = ...) -> int: ...
else:
def index(self, x: Any) -> int: ...
@overload
@overload
def index(self, object: _T, start: int = ..., stop: int = ...) -> int: ...
def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ...
else:
def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) ->
None: ...
@overload
@overload
def __getitem__(self, s: slice) -> List[_T]: ...
@overload
@overload
def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ...
# NOTE: Keyword arguments are special. If they are used, _KT must include
@overload
@overload
def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
@overload
def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ...
@overload
def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
@overload
def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
@overload
else:
@staticmethod
@overload
def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method
(mypy/issues#328)
@staticmethod
@overload
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
else:
class range(Sequence[int]):
start: int
stop: int
step: int
@overload
@overload
def __init__(self, start: int, stop: int, step: int = ...) -> None: ...
def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ...
@overload
@overload
else:
@overload
@overload
def __init__(self, start: int, stop: int, step: int = ...) -> None: ...
class property(object):
def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ...
long = int
NotImplemented: Any
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
class _PathLike(Generic[AnyStr]):
def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike[Any]],
mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ...
def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes], mode: str, flags: int
= ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ...
else:
def compile(source: Union[Text, mod], filename: Text, mode: Text, flags: int = ..., dont_inherit: int
= ...) -> Any: ...
def eval(__source: Union[Text, bytes, CodeType], __globals: Optional[Dict[str, Any]] = ..., __locals:
Optional[Mapping[str, Any]] = ...) -> Any: ...
def exec(__object: Union[str, bytes, CodeType], __globals: Optional[Dict[str, Any]] = ..., __locals:
Optional[Mapping[str, Any]] = ...) -> Any: ...
else:
@overload
@overload
else:
@overload
def filter(__function: Callable[[AnyStr], Any], __iterable: AnyStr) -> AnyStr: ... # type: ignore
@overload
def filter(__function: None, __iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ... # type: ignore
@overload
def filter(__function: Callable[[_T], Any], __iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ... # type:
ignore
@overload
@overload
def format(__o: object, __format_spec: str = ...) -> str: ... # TODO unicode
def getattr(__o: Any, name: Text, __default: Any = ...) -> Any: ...
else:
@overload
@overload
@overload
def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ...
def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ...
@overload
@overload
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
@overload
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
else:
@overload
@overload
__iter1: Iterable[_T1],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
@overload
@overload
__iter1: Iterable[_T1],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
@overload
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
@overload
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
@overload
def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def max(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def max(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ..., default: _VT) -> Union[_T, _VT]: ...
else:
@overload
def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def max(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def min(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def min(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def min(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ..., default: _VT) -> Union[_T, _VT]: ...
else:
@overload
def min(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def min(__iterable: Iterable[_T], *, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
@overload
def open(file: Union[str, bytes, int, _PathLike[Any]], mode: str = ..., buffering: int = ..., encoding:
Optional[str] = ...,
def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ...,
else:
def open(name: Union[unicode, int], mode: unicode = ..., buffering: int = ...) -> BinaryIO: ...
class _Writer(Protocol):
def print(
*values: object, sep: Optional[Text] = ..., end: Optional[Text] = ..., file: Optional[_Writer] = ...,
flush: bool = ...
class _Writer(Protocol):
def print(*values: object, sep: Optional[Text] = ..., end: Optional[Text] = ..., file: Optional[_Writer]
= ...) -> None: ...
@overload
def pow(__x: int, __y: int) -> Any: ... # The return type can be int or float, depending on y
@overload
def pow(__x: int, __y: int, __z: int) -> Any: ...
@overload
@overload
def pow(__x: float, __y: float, __z: float) -> float: ...
def range(__x: int, __y: int = ..., __step: int = ...) -> List[int]: ...
@overload
def reduce(__function: Callable[[_T, _S], _T], __iterable: Iterable[_S], __initializer: _T) -> _T: ...
@overload
def reduce(__function: Callable[[_T, _T], _T], __iterable: Iterable[_T]) -> _T: ...
@overload
@overload
@overload
def round(number: float) -> int: ...
@overload
@overload
@overload
@overload
@overload
else:
@overload
@overload
@overload
@overload
def setattr(__object: Any, __name: Text, __value: Any) -> None: ...
else:
@overload
def sum(__iterable: Iterable[_T]) -> Union[_T, int]: ...
@overload
@overload
@overload
@overload
@overload
@overload
__iter4: Iterable[_T4], __iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
else:
@overload
@overload
@overload
def zip(__iter1: Iterable[_T1], __iter2: Iterable[_T2],
@overload
@overload
__iter4: Iterable[_T4], __iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
Ellipsis: ellipsis
class buffer(Sized):
def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ...
class BaseException(object):
message: Any
__cause__: Optional[BaseException]
__context__: Optional[BaseException]
__suppress_context__: bool
__traceback__: Optional[TracebackType]
def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ...
class SystemExit(BaseException):
code: int
class StopIteration(Exception):
value: Any
if sys.version_info >= (3,):
_StandardError = Exception
class OSError(Exception):
errno: int
strerror: str
filename: Any
filename2: Any
EnvironmentError = OSError
IOError = OSError
else:
_StandardError = StandardError
class EnvironmentError(StandardError):
errno: int
strerror: str
filename: str
class ImportError(_StandardError):
def __init__(self, *args, name: Optional[str] = ..., path: Optional[str] = ...) -> None: ...
name: Optional[str]
path: Optional[str]
class LookupError(_StandardError): ...
class StopAsyncIteration(Exception):
value: Any
class SyntaxError(_StandardError):
msg: str
lineno: int
offset: Optional[int]
text: Optional[str]
filename: str
class WindowsError(OSError):
winerror: int
class BlockingIOError(OSError):
characters_written: int
class UnicodeDecodeError(UnicodeError):
encoding: str
object: bytes
start: int
end: int
reason: str
def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int,
class UnicodeEncodeError(UnicodeError):
encoding: str
object: Text
start: int
end: int
reason: str
def __init__(self, __encoding: str, __object: Text, __start: int, __end: int,
class file(BinaryIO):
@overload
def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ...
@overload
def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ...
@overload
def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ...
def seek(self, offset: int, whence: int = ...) -> int: ...