Avoid using string literals in type annotations (#2294)

This commit is contained in:
Yusuke Miyazaki
2018-07-03 12:23:29 +09:00
committed by Jelle Zijlstra
parent 25ad95de4f
commit 6192cce9d9
50 changed files with 175 additions and 175 deletions

View File

@@ -335,9 +335,9 @@ class _CursesWindow:
def delch(self, y: int, x: int) -> None: ...
def deleteln(self) -> None: ...
@overload
def derwin(self, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def derwin(self, begin_y: int, begin_x: int) -> _CursesWindow: ...
@overload
def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ...
def echochar(self, ch: _chtype, attr: int = ...) -> None: ...
def enclose(self, y: int, x: int) -> bool: ...
def erase(self) -> None: ...
@@ -406,13 +406,13 @@ class _CursesWindow:
def notimeout(self, yes: bool) -> None: ...
def noutrefresh(self) -> None: ...
@overload
def overlay(self, destwin: '_CursesWindow') -> None: ...
def overlay(self, destwin: _CursesWindow) -> None: ...
@overload
def overlay(self, destwin: '_CursesWindow', sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ...
def overlay(self, destwin: _CursesWindow, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ...
@overload
def overwrite(self, destwin: '_CursesWindow') -> None: ...
def overwrite(self, destwin: _CursesWindow) -> None: ...
@overload
def overwrite(self, destwin: '_CursesWindow', sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ...
def overwrite(self, destwin: _CursesWindow, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ...
def putwin(self, file: IO[Any]) -> None: ...
def redrawln(self, beg: int, num: int) -> None: ...
def redrawwin(self) -> None: ...
@@ -427,13 +427,13 @@ class _CursesWindow:
def standend(self) -> None: ...
def standout(self) -> None: ...
@overload
def subpad(self, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def subpad(self, begin_y: int, begin_x: int) -> _CursesWindow: ...
@overload
def subpad(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def subpad(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ...
@overload
def subwin(self, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def subwin(self, begin_y: int, begin_x: int) -> _CursesWindow: ...
@overload
def subwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ...
def subwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ...
def syncdown(self) -> None: ...
def syncok(self, flag: bool) -> None: ...
def syncup(self) -> None: ...

View File

@@ -10,7 +10,7 @@ import sys
from typing import Any, Dict, List, Optional
class ModuleSpec:
def __init__(self, name: str, loader: Optional['Loader'], *,
def __init__(self, name: str, loader: Optional[Loader], *,
origin: Optional[str] = ..., loader_state: Any = ...,
is_package: Optional[bool] = ...) -> None: ...
name = ... # type: str

View File

@@ -23,7 +23,7 @@ class make_scanner:
parse_float = ... # type: Any
strict = ... # type: bool
# TODO: 'context' needs the attrs above (ducktype), but not __call__.
def __init__(self, context: "make_scanner") -> None: ...
def __init__(self, context: make_scanner) -> None: ...
def __call__(self, string: str, index: int) -> Tuple[Any, int]: ...
def encode_basestring_ascii(s: str) -> str: ...

View File

@@ -6,7 +6,7 @@ _FuncT = TypeVar('_FuncT', bound=Callable[..., Any])
# Thesee definitions have special processing in mypy
class ABCMeta(type):
def register(cls: "ABCMeta", subclass: Type[_T]) -> Type[_T]: ...
def register(cls: ABCMeta, subclass: Type[_T]) -> Type[_T]: ...
def abstractmethod(callable: _FuncT) -> _FuncT: ...
class abstractproperty(property): ...

View File

@@ -1,8 +1,8 @@
from _curses import _CursesWindow
class _Curses_Panel: # type is <class '_curses_panel.curses panel'> (note the space in the class name)
def above(self) -> '_Curses_Panel': ...
def below(self) -> '_Curses_Panel': ...
def above(self) -> _Curses_Panel: ...
def below(self) -> _Curses_Panel: ...
def bottom(self) -> None: ...
def hidden(self) -> bool: ...
def hide(self) -> None: ...

View File

@@ -5,7 +5,7 @@ from email.message import Message
from email.policy import Policy
class Generator:
def clone(self, fp: TextIO) -> 'Generator': ...
def clone(self, fp: TextIO) -> Generator: ...
def write(self, s: str) -> None: ...
def __init__(self, outfp: TextIO, mangle_from_: bool = ...,
maxheaderlen: int = ..., *,
@@ -14,7 +14,7 @@ class Generator:
linesep: Optional[str] =...) -> None: ...
class BytesGenerator:
def clone(self, fp: TextIO) -> 'Generator': ...
def clone(self, fp: TextIO) -> Generator: ...
def write(self, s: str) -> None: ...
def __init__(self, outfp: TextIO, mangle_from_: bool = ...,
maxheaderlen: int = ..., *,

View File

@@ -12,7 +12,7 @@ class BaseHeader(str):
def defects(self) -> Tuple[MessageDefect, ...]: ...
@property
def max_count(self) -> Optional[int]: ...
def __new__(cls, name: str, value: Any) -> 'BaseHeader': ...
def __new__(cls, name: str, value: Any) -> BaseHeader: ...
def init(self, *args: Any, **kw: Any) -> None: ...
def fold(self, *, policy: Policy) -> str: ...

View File

@@ -26,7 +26,7 @@ class Message:
def is_multipart(self) -> bool: ...
def set_unixfrom(self, unixfrom: str) -> None: ...
def get_unixfrom(self) -> Optional[str]: ...
def attach(self, payload: 'Message') -> None: ...
def attach(self, payload: Message) -> None: ...
def get_payload(self, i: int = ..., decode: bool = ...) -> Optional[_PayloadType]: ...
def set_payload(self, payload: _PayloadType,
charset: _CharsetType = ...) -> None: ...
@@ -62,7 +62,7 @@ class Message:
def set_boundary(self, boundary: str) -> None: ...
def get_content_charset(self, failobj: _T = ...) -> Union[_T, str]: ...
def get_charsets(self, failobj: _T = ...) -> Union[_T, List[str]]: ...
def walk(self) -> Generator['Message', None, None]: ...
def walk(self) -> Generator[Message, None, None]: ...
if sys.version_info >= (3, 5):
def get_content_disposition(self) -> Optional[str]: ...
def as_string(self, unixfrom: bool = ..., maxheaderlen: int = ...,

View File

@@ -16,7 +16,7 @@ class Policy:
if sys.version_info >= (3, 5):
mange_from = ... # type: bool
def __init__(self, **kw: Any) -> None: ...
def clone(self, **kw: Any) -> 'Policy': ...
def clone(self, **kw: Any) -> Policy: ...
def handle_defect(self, obj: Message,
defect: MessageDefect) -> None: ...
def register_defect(self, obj: Message,

View File

@@ -100,7 +100,7 @@ if sys.version_info >= (3, 5):
def fileno(self) -> int: ...
def isclosed(self) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self) -> 'HTTPResponse': ...
def __enter__(self) -> HTTPResponse: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType]) -> bool: ...
@@ -122,7 +122,7 @@ else:
def getheaders(self) -> List[Tuple[str, str]]: ...
def fileno(self) -> int: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self) -> 'HTTPResponse': ...
def __enter__(self) -> HTTPResponse: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType]) -> bool: ...

View File

@@ -7,28 +7,28 @@ _T = TypeVar('_T')
class LoadError(OSError): ...
class CookieJar(Iterable['Cookie']):
def __init__(self, policy: Optional['CookiePolicy'] = ...) -> None: ...
class CookieJar(Iterable[Cookie]):
def __init__(self, policy: Optional[CookiePolicy] = ...) -> None: ...
def add_cookie_header(self, request: Request) -> None: ...
def extract_cookies(self, response: HTTPResponse,
request: Request) -> None: ...
def set_policy(self, policy: 'CookiePolicy') -> None: ...
def set_policy(self, policy: CookiePolicy) -> None: ...
def make_cookies(self, response: HTTPResponse,
request: Request) -> Sequence['Cookie']: ...
def set_cookie(self, cookie: 'Cookie') -> None: ...
def set_cookie_if_ok(self, cookie: 'Cookie',
request: Request) -> Sequence[Cookie]: ...
def set_cookie(self, cookie: Cookie) -> None: ...
def set_cookie_if_ok(self, cookie: Cookie,
request: Request) -> None: ...
def clear(self, domain: str = ..., path: str = ...,
name: str = ...) -> None: ...
def clear_session_cookies(self) -> None: ...
def __iter__(self) -> Iterator['Cookie']: ...
def __iter__(self) -> Iterator[Cookie]: ...
def __len__(self) -> int: ...
class FileCookieJar(CookieJar):
filename = ... # type: str
delayload = ... # type: bool
def __init__(self, filename: str = ..., delayload: bool = ...,
policy: Optional['CookiePolicy'] = ...) -> None: ...
policy: Optional[CookiePolicy] = ...) -> None: ...
def save(self, filename: Optional[str] = ..., ignore_discard: bool = ...,
ignore_expires: bool = ...) -> None: ...
def load(self, filename: Optional[str] = ..., ignore_discard: bool = ...,
@@ -44,8 +44,8 @@ class CookiePolicy:
netscape = ... # type: bool
rfc2965 = ... # type: bool
hide_cookie2 = ... # type: bool
def set_ok(self, cookie: 'Cookie', request: Request) -> bool: ...
def return_ok(self, cookie: 'Cookie', request: Request) -> bool: ...
def set_ok(self, cookie: Cookie, request: Request) -> bool: ...
def return_ok(self, cookie: Cookie, request: Request) -> bool: ...
def domain_return_ok(self, domain: str, request: Request) -> bool: ...
def path_return_ok(self, path: str, request: Request) -> bool: ...

View File

@@ -2,7 +2,7 @@
from typing import Generic, Dict, List, Mapping, MutableMapping, Optional, TypeVar, Union
_DataType = Union[str, Mapping[str, Union[str, 'Morsel']]]
_DataType = Union[str, Mapping[str, Union[str, Morsel]]]
_T = TypeVar('_T')
class CookieError(Exception): ...

View File

@@ -46,7 +46,7 @@ if sys.version_info >= (3, 5):
@classmethod
def factory(
cls, loader: importlib.abc.Loader
) -> Callable[..., 'LazyLoader']: ...
) -> Callable[..., LazyLoader]: ...
def create_module(
self, spec: importlib.machinery.ModuleSpec
) -> Optional[types.ModuleType]: ...

View File

@@ -100,34 +100,34 @@ def indentsize(line: str) -> int: ...
#
def signature(callable: Callable[..., Any],
*,
follow_wrapped: bool = ...) -> 'Signature': ...
follow_wrapped: bool = ...) -> Signature: ...
class Signature:
def __init__(self,
parameters: Optional[Sequence['Parameter']] = ...,
parameters: Optional[Sequence[Parameter]] = ...,
*,
return_annotation: Any = ...) -> None: ...
# TODO: can we be more specific here?
empty: object = ...
parameters: Mapping[str, 'Parameter']
parameters: Mapping[str, Parameter]
# TODO: can we be more specific here?
return_annotation: Any
def bind(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...
def bind_partial(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...
def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def replace(self,
*,
parameters: Optional[Sequence['Parameter']] = ...,
return_annotation: Any = ...) -> 'Signature': ...
parameters: Optional[Sequence[Parameter]] = ...,
return_annotation: Any = ...) -> Signature: ...
if sys.version_info >= (3, 5):
@classmethod
def from_callable(cls,
obj: Callable[..., Any],
*,
follow_wrapped: bool = ...) -> 'Signature': ...
follow_wrapped: bool = ...) -> Signature: ...
# The name is the same as the enum's name in CPython
class _ParameterKind: ...
@@ -156,7 +156,7 @@ class Parameter:
name: Optional[str] = ...,
kind: Optional[_ParameterKind] = ...,
default: Any = ...,
annotation: Any = ...) -> 'Parameter': ...
annotation: Any = ...) -> Parameter: ...
class BoundArguments:
arguments: MutableMapping[str, Any]
@@ -174,7 +174,7 @@ class BoundArguments:
# TODO: The actual return type should be List[_ClassTreeItem] but mypy doesn't
# seem to be supporting this at the moment:
# _ClassTreeItem = Union[List['_ClassTreeItem'], Tuple[type, Tuple[type, ...]]]
# _ClassTreeItem = Union[List[_ClassTreeItem], Tuple[type, Tuple[type, ...]]]
def getclasstree(classes: List[type], unique: bool = ...) -> Any: ...
ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),

View File

@@ -85,7 +85,7 @@ class BytesIO(BinaryIO):
# copied from IOBase
def __iter__(self) -> Iterator[bytes]: ...
def __next__(self) -> bytes: ...
def __enter__(self) -> 'BytesIO': ...
def __enter__(self) -> BytesIO: ...
def __exit__(self, t: Optional[Type[BaseException]] = ..., value: Optional[BaseException] = ...,
traceback: Optional[TracebackType] = ...) -> bool: ...
def close(self) -> None: ...
@@ -186,7 +186,7 @@ class TextIOWrapper(TextIO):
newlines = ... # type: Union[str, Tuple[str, ...], None]
def __iter__(self) -> Iterator[str]: ...
def __next__(self) -> str: ...
def __enter__(self) -> 'TextIO': ...
def __enter__(self) -> TextIO: ...
def detach(self) -> IOBase: ...
def write(self, s: str) -> int: ...
def readline(self, size: int = ...) -> str: ...
@@ -202,7 +202,7 @@ class StringIO(TextIOWrapper):
# as a read-only property on IO[].
name: Any
def getvalue(self) -> str: ...
def __enter__(self) -> 'StringIO': ...
def __enter__(self) -> StringIO: ...
class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
def decode(self, input: bytes, final: bool = ...) -> str: ...

View File

@@ -7,7 +7,7 @@ import os
class Template:
def __init__(self) -> None: ...
def reset(self) -> None: ...
def clone(self) -> 'Template': ...
def clone(self) -> Template: ...
def debug(self, flag: bool) -> None: ...
def append(self, cmd: str, kind: str) -> None: ...
def prepend(self, cmd: str, kind: str) -> None: ...

View File

@@ -35,7 +35,7 @@ class BaseServer:
def verify_request(self, request: bytes,
client_address: Tuple[str, int]) -> bool: ...
if sys.version_info >= (3, 6):
def __enter__(self) -> 'BaseServer': ...
def __enter__(self) -> BaseServer: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType]) -> bool: ...

View File

@@ -270,7 +270,7 @@ class Popen:
def send_signal(self, signal: int) -> None: ...
def terminate(self) -> None: ...
def kill(self) -> None: ...
def __enter__(self) -> 'Popen': ...
def __enter__(self) -> Popen: ...
def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ...
# The result really is always a str.

View File

@@ -33,7 +33,7 @@ class FunctionType:
__annotations__ = ... # type: Dict[str, Any]
__kwdefaults__ = ... # type: Dict[str, Any]
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ...
def __get__(self, obj: Optional[object], type: Optional[type]) -> MethodType: ...
LambdaType = FunctionType
class CodeType:
@@ -89,14 +89,14 @@ class GeneratorType:
gi_frame = ... # type: FrameType
gi_running = ... # type: bool
gi_yieldfrom = ... # type: Optional[GeneratorType]
def __iter__(self) -> 'GeneratorType': ...
def __iter__(self) -> GeneratorType: ...
def __next__(self) -> Any: ...
def close(self) -> None: ...
def send(self, arg: Any) -> Any: ...
@overload
def throw(self, val: BaseException) -> Any: ...
@overload
def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
def throw(self, typ: type, val: BaseException = ..., tb: TracebackType = ...) -> Any: ...
if sys.version_info >= (3, 6):
class AsyncGeneratorType(Generic[_T_co, _T_contra]):
@@ -123,7 +123,7 @@ class CoroutineType:
@overload
def throw(self, val: BaseException) -> Any: ...
@overload
def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
def throw(self, typ: type, val: BaseException = ..., tb: TracebackType = ...) -> Any: ...
class _StaticFunctionType:
"""Fictional type to correct the type of MethodType.__func__.
@@ -138,7 +138,7 @@ class _StaticFunctionType:
similar to wrapping a function in staticmethod() at runtime to prevent it
being bound as a method.
"""
def __get__(self, obj: Optional[object], type: Optional[type]) -> 'FunctionType': ...
def __get__(self, obj: Optional[object], type: Optional[type]) -> FunctionType: ...
class MethodType:
__func__ = ... # type: _StaticFunctionType

View File

@@ -474,7 +474,7 @@ class Match(Generic[AnyStr]):
# The regular expression object whose match() or search() method produced
# this match instance.
re = ... # type: 'Pattern[AnyStr]'
re = ... # type: Pattern[AnyStr]
def expand(self, template: AnyStr) -> AnyStr: ...

View File

@@ -18,11 +18,11 @@ class _ResultMixinBase(Generic[AnyStr]):
def geturl(self) -> AnyStr: ...
class _ResultMixinStr(_ResultMixinBase[str]):
def encode(self, encoding: str = ..., errors: str = ...) -> '_ResultMixinBytes': ...
def encode(self, encoding: str = ..., errors: str = ...) -> _ResultMixinBytes: ...
class _ResultMixinBytes(_ResultMixinBase[str]):
def decode(self, encoding: str = ..., errors: str = ...) -> '_ResultMixinStr': ...
def decode(self, encoding: str = ..., errors: str = ...) -> _ResultMixinStr: ...
class _NetlocResultMixinBase(Generic[AnyStr]):

View File

@@ -17,7 +17,7 @@ _UrlopenRet = Union[HTTPResponse, addinfourl]
def urlopen(
url: Union[str, 'Request'], data: Optional[bytes] = ...,
url: Union[str, Request], data: Optional[bytes] = ...,
timeout: float = ..., *, cafile: Optional[str] = ...,
capath: Optional[str] = ..., cadefault: bool = ...,
context: Optional[ssl.SSLContext] = ...