From d389ef3d854cf38d1e52d04ad2d4cfc5f45a0e29 Mon Sep 17 00:00:00 2001 From: Martin DeMello Date: Wed, 27 Sep 2017 07:57:13 -0700 Subject: [PATCH] Remove a few files from the pytype blacklist. (#1628) Fixes the following issues: * Literals rather than ... for default values * None rather than ... for default value of typed variable * Literals rather than ... # type for top level constants * # Foo rather than # type: Foo * return value of init not set to None --- stdlib/3/email/policy.pyi | 3 +-- stdlib/3/gzip.pyi | 22 +++++++++++----------- stdlib/3/json/decoder.pyi | 8 ++++---- stdlib/3/json/encoder.pyi | 2 +- stdlib/3/tkinter/__init__.pyi | 16 ++++++++-------- stdlib/3/unittest/mock.pyi | 6 +++--- stdlib/3/urllib/parse.pyi | 18 +----------------- tests/pytype_blacklist.txt | 12 ------------ 8 files changed, 29 insertions(+), 58 deletions(-) diff --git a/stdlib/3/email/policy.pyi b/stdlib/3/email/policy.pyi index 97f0c519c..615200220 100644 --- a/stdlib/3/email/policy.pyi +++ b/stdlib/3/email/policy.pyi @@ -42,8 +42,7 @@ if sys.version_info >= (3, 3): def header_source_parse(self, sourcelines: List[str]) -> str: ... def header_store_parse(self, name: str, value: str) -> Tuple[str, str]: ... - def header_fetch_parse(self, name: str, # type: ignore - value: str) -> Union[str, Header]: ... + def header_fetch_parse(self, name: str, value: str) -> Union[str, Header]: ... # type: ignore def fold(self, name: str, value: str) -> str: ... def fold_binary(self, name: str, value: str) -> bytes: ... diff --git a/stdlib/3/gzip.pyi b/stdlib/3/gzip.pyi index c4420fb1c..8a6f43ecb 100644 --- a/stdlib/3/gzip.pyi +++ b/stdlib/3/gzip.pyi @@ -1,13 +1,13 @@ -from typing import Any +from typing import Any, Optional import _compression -def open(filename, mode='', compresslevel=9, encoding=None, errors=None, newline=None): ... +def open(filename, mode: str = ..., compresslevel: int = ..., encoding=None, errors=None, newline=None): ... class _PaddedFile: file = ... # type: Any - def __init__(self, f, prepend=b''): ... + def __init__(self, f, prepend: bytes = ...) -> None: ... def read(self, size): ... - def prepend(self, prepend=b''): ... + def prepend(self, prepend: bytes = ...): ... def seek(self, off): ... def seekable(self): ... @@ -17,15 +17,15 @@ class GzipFile(_compression.BaseStream): name = ... # type: Any compress = ... # type: Any fileobj = ... # type: Any - def __init__(self, filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None): ... + def __init__(self, filename=None, mode=None, compresslevel: int = ..., fileobj=None, mtime=None) -> None: ... @property def filename(self): ... @property def mtime(self): ... crc = ... # type: Any def write(self, data): ... - def read(self, size=-1): ... - def read1(self, size=-1): ... + def read(self, size: Optional[int] = ...): ... + def read1(self, size: int = ...): ... def peek(self, n): ... @property def closed(self): ... @@ -37,11 +37,11 @@ class GzipFile(_compression.BaseStream): def writable(self): ... def seekable(self): ... def seek(self, offset, whence=...): ... - def readline(self, size=-1): ... + def readline(self, size: int = ...): ... class _GzipReader(_compression.DecompressReader): - def __init__(self, fp): ... - def read(self, size=-1): ... + def __init__(self, fp) -> None: ... + def read(self, size: int = ...): ... -def compress(data, compresslevel=9): ... +def compress(data, compresslevel: int = ...): ... def decompress(data): ... diff --git a/stdlib/3/json/decoder.pyi b/stdlib/3/json/decoder.pyi index 1c3e9a05b..164fcadce 100644 --- a/stdlib/3/json/decoder.pyi +++ b/stdlib/3/json/decoder.pyi @@ -11,12 +11,12 @@ if sys.version_info >= (3, 5): def __init__(self, msg: str, doc: str, pos: int) -> None: ... class JSONDecoder: - object_hook = None # type: Callable[[Dict[str, Any]], Any] - parse_float = ... # Callable[[str], Any] - parse_int = ... # Callable[[str], Any] + object_hook = ... # type: Callable[[Dict[str, Any]], Any] + parse_float = ... # type: Callable[[str], Any] + parse_int = ... # type: Callable[[str], Any] parse_constant = ... # Callable[[str], Any] strict = ... # type: bool - object_pairs_hook = None # type: Callable[[List[Tuple[str, Any]]], Any] + object_pairs_hook = ... # type: Callable[[List[Tuple[str, Any]]], Any] def __init__(self, object_hook: Optional[Callable[[Dict[str, Any]], Any]] = None, parse_float: Optional[Callable[[str], Any]] = None, diff --git a/stdlib/3/json/encoder.pyi b/stdlib/3/json/encoder.pyi index c423c182a..ced7168b9 100644 --- a/stdlib/3/json/encoder.pyi +++ b/stdlib/3/json/encoder.pyi @@ -9,7 +9,7 @@ class JSONEncoder: check_circular = ... # type: bool allow_nan = ... # type: bool sort_keys = ... # type: bool - indent = None # type: int + indent = ... # type: int def __init__(self, skipkeys: bool = ..., ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., sort_keys: bool = ..., diff --git a/stdlib/3/tkinter/__init__.pyi b/stdlib/3/tkinter/__init__.pyi index 4ef707930..f7f7f8cf0 100644 --- a/stdlib/3/tkinter/__init__.pyi +++ b/stdlib/3/tkinter/__init__.pyi @@ -57,12 +57,12 @@ class Misc: def tk_bisque(self): ... def tk_setPalette(self, *args, **kw): ... def tk_menuBar(self, *args): ... - def wait_variable(self, name=''): ... + def wait_variable(self, name: str = ...): ... waitvar = ... # type: Any def wait_window(self, window=None): ... def wait_visibility(self, window=None): ... - def setvar(self, name='', value=''): ... - def getvar(self, name=''): ... + def setvar(self, name: str = ..., value: str = ...): ... + def getvar(self, name: str = ...): ... def getint(self, s): ... def getdouble(self, s): ... def getboolean(self, s): ... @@ -278,14 +278,14 @@ class Tk(Misc, Wm): master = ... # type: Any children = ... # type: Any tk = ... # type: Any - def __init__(self, screenName=None, baseName=None, className='', useTk=1, sync=0, use=None): ... + def __init__(self, screenName=None, baseName=None, className: str = ..., useTk=1, sync=0, use=None) -> None: ... def loadtk(self): ... def destroy(self): ... def readprofile(self, baseName, className): ... def report_callback_exception(self, exc, val, tb): ... def __getattr__(self, attr): ... -def Tcl(screenName=None, baseName=None, className='', useTk=0): ... +def Tcl(screenName=None, baseName=None, className: str = ..., useTk=0): ... class Pack: def pack_configure(self, cnf=..., **kw): ... @@ -461,7 +461,7 @@ class Listbox(Widget, XView, YView): class Menu(Widget): def __init__(self, master=None, cnf=..., **kw): ... - def tk_popup(self, x, y, entry=''): ... + def tk_popup(self, x, y, entry: str = ...): ... def tk_bindForTraversal(self): ... def activate(self, index): ... def add(self, itemType, cnf=..., **kw): ... @@ -603,8 +603,8 @@ class PhotoImage(Image): def cget(self, option): ... def __getitem__(self, key): ... def copy(self): ... - def zoom(self, x, y=''): ... - def subsample(self, x, y=''): ... + def zoom(self, x, y: str = ...): ... + def subsample(self, x, y: str = ...): ... def get(self, x, y): ... def put(self, data, to=None): ... def write(self, filename, format=None, from_coords=None): ... diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index 4c78a0f83..2002f8933 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -38,7 +38,7 @@ if sys.version_info >= (3, 3): # expecting other classes (as is Mock's purpose) class NonCallableMock(Any): # type: ignore def __new__(cls, *args: Any, **kw: Any) -> Any: ... - def __init__(self, spec: Optional[Any] = None, wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any ='', _new_parent: Optional[Any] = None, _spec_as_instance: Any = False, _eat_self: Optional[Any] = None, unsafe: Any = False, **kwargs: Any) -> None: ... + def __init__(self, spec: Optional[Any] = None, wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any = ..., _new_parent: Optional[Any] = None, _spec_as_instance: Any = False, _eat_self: Optional[Any] = None, unsafe: Any = False, **kwargs: Any) -> None: ... def attach_mock(self, mock: Any, attribute: Any) -> Any: ... def mock_add_spec(self, spec: Any, spec_set: Any = False) -> Any: ... return_value = ... # type: Any @@ -64,7 +64,7 @@ if sys.version_info >= (3, 3): class CallableMixin(Base): side_effect = ... # type: Any - def __init__(self, spec: Optional[Any] = None, side_effect: Optional[Any] = None, return_value: Any = ..., wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any = '', _new_parent: Optional[Any] = None, **kwargs: Any) -> None: ... + def __init__(self, spec: Optional[Any] = None, side_effect: Optional[Any] = None, return_value: Any = ..., wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any = ..., _new_parent: Optional[Any] = None, **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... class Mock(CallableMixin, NonCallableMock): @@ -167,7 +167,7 @@ if sys.version_info >= (3, 3): name = ... # type: Any def __init__(self, spec: Any, spec_set: Any = False, parent: Optional[Any] = None, name: Optional[Any] = None, ids: Optional[Any] = None, instance: Any = False) -> None: ... - def mock_open(mock: Optional[Any] = None, read_data: Any = '') -> Any: ... + def mock_open(mock: Optional[Any] = None, read_data: Any = ...) -> Any: ... class PropertyMock(Mock): def __get__(self, obj: Any, obj_type: Any) -> Any: ... diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index 637fa5fa6..c8f4c1101 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -4,23 +4,7 @@ import sys _Str = Union[bytes, str] -__all__ = ( - 'urlparse', - 'urlunparse', - 'urljoin', - 'urldefrag', - 'urlsplit', - 'urlunsplit', - 'urlencode', - 'parse_qs', - 'parse_qsl', - 'quote', - 'quote_plus', - 'quote_from_bytes', - 'unquote', - 'unquote_plus', - 'unquote_to_bytes' -) +__all__ = ... # type: Tuple[str] uses_relative = ... # type: List[str] uses_netloc = ... # type: List[str] diff --git a/tests/pytype_blacklist.txt b/tests/pytype_blacklist.txt index 53377dbe8..332c8a144 100644 --- a/tests/pytype_blacklist.txt +++ b/tests/pytype_blacklist.txt @@ -8,9 +8,6 @@ stdlib/2/typing.pyi stdlib/3/builtins.pyi stdlib/3/typing.pyi -# Because of 'class ForkProcess(Any): # type: ignore' -stdlib/3/multiprocessing/context.pyi - # Because of 'from . import path': stdlib/2/os/__init__.pyi stdlib/3/os/__init__.pyi @@ -23,25 +20,17 @@ stdlib/3/concurrent/futures/__init__.pyi stdlib/3/concurrent/futures/_base.pyi stdlib/3/concurrent/futures/process.pyi stdlib/3/concurrent/futures/thread.pyi -stdlib/3/email/policy.pyi -stdlib/3/fileinput.pyi -stdlib/3/gzip.pyi stdlib/3/http/__init__.pyi stdlib/3/http/cookiejar.pyi stdlib/3/inspect.pyi stdlib/3/json/__init__.pyi -stdlib/3/json/decoder.pyi -stdlib/3/json/encoder.pyi stdlib/3/ssl.pyi stdlib/3/subprocess.pyi stdlib/3/sys.pyi stdlib/3/textwrap.pyi stdlib/3/time.pyi -stdlib/3/tkinter/__init__.pyi stdlib/3/types.pyi stdlib/3/unittest/__init__.pyi -stdlib/3/unittest/mock.pyi -stdlib/3/urllib/parse.pyi stdlib/3/wsgiref/types.pyi stdlib/3.4/asyncio/events.pyi stdlib/3.4/asyncio/futures.pyi @@ -50,4 +39,3 @@ stdlib/3.4/asyncio/queues.pyi stdlib/3.4/asyncio/streams.pyi stdlib/3.4/asyncio/subprocess.pyi stdlib/3.4/asyncio/tasks.pyi -stdlib/3.4/enum.pyi