apply black and isort (#4287)

* apply black and isort

* move some type ignores
This commit is contained in:
Jelle Zijlstra
2020-06-28 13:31:00 -07:00
committed by GitHub
parent fe58699ca5
commit 5d553c9584
800 changed files with 13875 additions and 10332 deletions

View File

@@ -1,9 +1,9 @@
# Stubs for typing
import sys
from abc import abstractmethod, ABCMeta
from types import CodeType, FrameType, TracebackType
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from abc import ABCMeta, abstractmethod
from types import CodeType, FrameType, TracebackType
# Definitions of special type checking related constructs. Their definitions
# are not used, so their value does not matter.
@@ -17,7 +17,14 @@ class TypeVar:
__constraints__: Tuple[Type[Any], ...]
__covariant__: bool
__contravariant__: bool
def __init__(self, name: str, *constraints: Type[Any], bound: Optional[Type[Any]] = ..., covariant: bool = ..., contravariant: bool = ...) -> None: ...
def __init__(
self,
name: str,
*constraints: Type[Any],
bound: Optional[Type[Any]] = ...,
covariant: bool = ...,
contravariant: bool = ...,
) -> None: ...
_promote = object()
@@ -35,7 +42,7 @@ Type: _SpecialForm = ...
ClassVar: _SpecialForm = ...
if sys.version_info >= (3, 8):
Final: _SpecialForm = ...
_F = TypeVar('_F', bound=Callable[..., Any])
_F = TypeVar("_F", bound=Callable[..., Any])
def final(f: _F) -> _F: ...
Literal: _SpecialForm = ...
# TypedDict is a (non-subscriptable) special form.
@@ -50,19 +57,20 @@ if sys.version_info < (3, 7):
NoReturn = Union[None]
# These type variables are used by the container types.
_T = TypeVar('_T')
_S = TypeVar('_S')
_KT = TypeVar('_KT') # Key type.
_VT = TypeVar('_VT') # Value type.
_T_co = TypeVar('_T_co', covariant=True) # Any type covariant containers.
_V_co = TypeVar('_V_co', covariant=True) # Any type covariant containers.
_KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers.
_VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers.
_T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant.
_TC = TypeVar('_TC', bound=Type[object])
_T = TypeVar("_T")
_S = TypeVar("_S")
_KT = TypeVar("_KT") # Key type.
_VT = TypeVar("_VT") # Value type.
_T_co = TypeVar("_T_co", covariant=True) # Any type covariant containers.
_V_co = TypeVar("_V_co", covariant=True) # Any type covariant containers.
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
_T_contra = TypeVar("_T_contra", contravariant=True) # Ditto contravariant.
_TC = TypeVar("_TC", bound=Type[object])
_C = TypeVar("_C", bound=Callable[..., Any])
no_type_check = object()
def no_type_check_decorator(decorator: _C) -> _C: ...
# Type aliases and type constructors
@@ -87,12 +95,11 @@ if sys.version_info >= (3, 9):
Annotated: _SpecialForm = ...
# Predefined type variables.
AnyStr = TypeVar('AnyStr', str, bytes)
AnyStr = TypeVar("AnyStr", str, bytes)
# Abstract base classes.
def runtime_checkable(cls: _TC) -> _TC: ...
@runtime_checkable
class SupportsInt(Protocol, metaclass=ABCMeta):
@abstractmethod
@@ -165,25 +172,20 @@ class Iterator(Iterable[_T_co], Protocol[_T_co]):
class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
@abstractmethod
def __next__(self) -> _T_co: ...
@abstractmethod
def send(self, __value: _T_contra) -> _T_co: ...
@overload
@abstractmethod
def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ...,
__tb: Optional[TracebackType] = ...) -> _T_co: ...
def throw(
self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ...
) -> _T_co: ...
@overload
@abstractmethod
def throw(self, __typ: BaseException, __val: None = ...,
__tb: Optional[TracebackType] = ...) -> _T_co: ...
def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> _T_co: ...
@abstractmethod
def close(self) -> None: ...
@abstractmethod
def __iter__(self) -> Generator[_T_co, _T_contra, _V_co]: ...
@property
def gi_code(self) -> CodeType: ...
@property
@@ -207,27 +209,24 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]):
def cr_frame(self) -> FrameType: ...
@property
def cr_running(self) -> bool: ...
@abstractmethod
def send(self, __value: _T_contra) -> _T_co: ...
@overload
@abstractmethod
def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ...,
__tb: Optional[TracebackType] = ...) -> _T_co: ...
def throw(
self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ...
) -> _T_co: ...
@overload
@abstractmethod
def throw(self, __typ: BaseException, __val: None = ...,
__tb: Optional[TracebackType] = ...) -> _T_co: ...
def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> _T_co: ...
@abstractmethod
def close(self) -> None: ...
# NOTE: This type does not exist in typing.py or PEP 484.
# The parameters correspond to Generator, but the 4th is the original type.
class AwaitableGenerator(Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co],
Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta): ...
class AwaitableGenerator(
Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta
): ...
@runtime_checkable
class AsyncIterable(Protocol[_T_co]):
@@ -235,8 +234,7 @@ class AsyncIterable(Protocol[_T_co]):
def __aiter__(self) -> AsyncIterator[_T_co]: ...
@runtime_checkable
class AsyncIterator(AsyncIterable[_T_co],
Protocol[_T_co]):
class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
@abstractmethod
def __anext__(self) -> Awaitable[_T_co]: ...
def __aiter__(self) -> AsyncIterator[_T_co]: ...
@@ -245,25 +243,20 @@ if sys.version_info >= (3, 6):
class AsyncGenerator(AsyncIterator[_T_co], Generic[_T_co, _T_contra]):
@abstractmethod
def __anext__(self) -> Awaitable[_T_co]: ...
@abstractmethod
def asend(self, __value: _T_contra) -> Awaitable[_T_co]: ...
@overload
@abstractmethod
def athrow(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ...,
__tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ...
def athrow(
self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ...
) -> Awaitable[_T_co]: ...
@overload
@abstractmethod
def athrow(self, __typ: BaseException, __val: None = ...,
__tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ...
def athrow(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ...
@abstractmethod
def aclose(self) -> Awaitable[None]: ...
@abstractmethod
def __aiter__(self) -> AsyncGenerator[_T_co, _T_contra]: ...
@property
def ag_await(self) -> Any: ...
@property
@@ -278,14 +271,12 @@ class Container(Protocol[_T_co]):
@abstractmethod
def __contains__(self, __x: object) -> bool: ...
if sys.version_info >= (3, 6):
@runtime_checkable
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
# Implement Sized (but don't have it as a base class).
@abstractmethod
def __len__(self) -> int: ...
_Collection = Collection
else:
@runtime_checkable
@@ -410,26 +401,25 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
@runtime_checkable
class ContextManager(Protocol[_T_co]):
def __enter__(self) -> _T_co: ...
def __exit__(self, __exc_type: Optional[Type[BaseException]],
__exc_value: Optional[BaseException],
__traceback: Optional[TracebackType]) -> Optional[bool]: ...
def __exit__(
self,
__exc_type: Optional[Type[BaseException]],
__exc_value: Optional[BaseException],
__traceback: Optional[TracebackType],
) -> Optional[bool]: ...
@runtime_checkable
class AsyncContextManager(Protocol[_T_co]):
def __aenter__(self) -> Awaitable[_T_co]: ...
def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType],
) -> Awaitable[Optional[bool]]: ...
class Mapping(_Collection[_KT], Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
# see discussion in https: //github.com/python/typing/pull/273.
@abstractmethod
def __getitem__(self, k: _KT) -> _VT_co:
...
def __getitem__(self, k: _KT) -> _VT_co: ...
# Mixin methods
@overload
def get(self, key: _KT) -> Optional[_VT_co]: ...
@@ -445,7 +435,6 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
def __setitem__(self, k: _KT, v: _VT) -> None: ...
@abstractmethod
def __delitem__(self, v: _KT) -> None: ...
def clear(self) -> None: ...
@overload
def pop(self, key: _KT) -> _VT: ...
@@ -515,7 +504,6 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
def write(self, s: AnyStr) -> int: ...
@abstractmethod
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
@abstractmethod
def __next__(self) -> AnyStr: ...
@abstractmethod
@@ -523,8 +511,9 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
@abstractmethod
def __enter__(self) -> IO[AnyStr]: ...
@abstractmethod
def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException],
traceback: Optional[TracebackType]) -> Optional[bool]: ...
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]
) -> Optional[bool]: ...
class BinaryIO(IO[bytes]):
# TODO readinto
@@ -560,20 +549,12 @@ class Match(Generic[AnyStr]):
# The regular expression object whose match() or search() method produced
# this match instance.
re: Pattern[AnyStr]
def expand(self, template: AnyStr) -> AnyStr: ...
# TODO: The return for a group may be None, except if __group is 0 or not given.
@overload
def group(self, __group: Union[str, int] = ...) -> AnyStr: ...
@overload
def group(
self,
__group1: Union[str, int],
__group2: Union[str, int],
*groups: Union[str, int],
) -> Tuple[AnyStr, ...]: ...
def group(self, __group1: Union[str, int], __group2: Union[str, int], *groups: Union[str, int],) -> Tuple[AnyStr, ...]: ...
def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ...
def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ...
def start(self, __group: Union[int, str] = ...) -> int: ...
@@ -589,45 +570,37 @@ class Pattern(Generic[AnyStr]):
groupindex: Mapping[str, int]
groups: int
pattern: AnyStr
def search(self, string: AnyStr, pos: int = ...,
endpos: int = ...) -> Optional[Match[AnyStr]]: ...
def match(self, string: AnyStr, pos: int = ...,
endpos: int = ...) -> Optional[Match[AnyStr]]: ...
def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Optional[Match[AnyStr]]: ...
def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Optional[Match[AnyStr]]: ...
# New in Python 3.4
def fullmatch(self, string: AnyStr, pos: int = ...,
endpos: int = ...) -> Optional[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 findall(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> list[Any]: ...
def finditer(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Iterator[Match[AnyStr]]: ...
@overload
def sub(self, repl: AnyStr, string: AnyStr,
count: int = ...) -> AnyStr: ...
def sub(self, repl: AnyStr, string: AnyStr, count: int = ...) -> AnyStr: ...
@overload
def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,
count: int = ...) -> AnyStr: ...
def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ...
@overload
def subn(self, repl: AnyStr, string: AnyStr,
count: int = ...) -> Tuple[AnyStr, int]: ...
def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> Tuple[AnyStr, int]: ...
@overload
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,
count: int = ...) -> Tuple[AnyStr, int]: ...
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> Tuple[AnyStr, int]: ...
# Functions
if sys.version_info >= (3, 9):
def get_type_hints(
obj: Callable[..., Any], globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ...,
include_extras: bool = ...
obj: Callable[..., Any],
globalns: Optional[Dict[str, Any]] = ...,
localns: Optional[Dict[str, Any]] = ...,
include_extras: bool = ...,
) -> Dict[str, Any]: ...
else:
def get_type_hints(
obj: Callable[..., Any], globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ...,
) -> Dict[str, Any]: ...
if sys.version_info >= (3, 8):
def get_origin(tp: Any) -> Optional[Any]: ...
def get_args(tp: Any) -> Tuple[Any, ...]: ...
@@ -645,13 +618,9 @@ class NamedTuple(Tuple[Any, ...]):
_field_defaults: Dict[str, Any] = ...
_fields: Tuple[str, ...]
_source: str
def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ...,
**kwargs: Any) -> None: ...
def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., **kwargs: Any) -> None: ...
@classmethod
def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ...
if sys.version_info >= (3, 8):
def _asdict(self) -> Dict[str, Any]: ...
else:
@@ -686,8 +655,7 @@ if sys.version_info >= (3, 7):
__forward_value__: Optional[Any]
__forward_is_argument__: bool
def __init__(self, arg: str, is_argument: bool = ...) -> None: ...
def _evaluate(self, globalns: Optional[Dict[str, Any]],
localns: Optional[Dict[str, Any]]) -> Optional[Any]: ...
def _evaluate(self, globalns: Optional[Dict[str, Any]], localns: Optional[Dict[str, Any]]) -> Optional[Any]: ...
def __eq__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
def __repr__(self) -> str: ...