diff --git a/.flake8 b/.flake8 index 383fc9988..1746f3c0f 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,6 @@ ignore = F401, F811, E127, E128, E301, E302, E305, E501, E701, E704 # Errors that we need to fix before enabling flake8 by default: # 921 F821 undefined name -# 52 E402 module-level import not at top of file # 48 E225 missing whitespace around operator # 28 E116 unexpected indentation (comment) # 26 F403 from * import used @@ -32,5 +31,4 @@ ignore = F401, F811, E127, E128, E301, E302, E305, E501, E701, E704 # 4 E114 indentation is not a multiple of four # 3 E303 too many blank lines # 2 B303 __metaclass__ use on Python 3 -# 1 E401 multiple imports on one line # 1 E202 whitespace before ) diff --git a/stdlib/2/io.pyi b/stdlib/2/io.pyi index 8724ffd11..5fa20c7a7 100644 --- a/stdlib/2/io.pyi +++ b/stdlib/2/io.pyi @@ -4,10 +4,10 @@ # Only a subset of functionality is included. -DEFAULT_BUFFER_SIZE = 0 - from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any, Union +DEFAULT_BUFFER_SIZE = 0 + def open(file: Union[str, unicode, int], mode: unicode = ..., buffering: int = ..., encoding: unicode = ..., errors: unicode = ..., newline: unicode = ..., diff --git a/stdlib/2and3/asynchat.pyi b/stdlib/2and3/asynchat.pyi index f4a57a4aa..b5cf3c082 100644 --- a/stdlib/2and3/asynchat.pyi +++ b/stdlib/2and3/asynchat.pyi @@ -1,8 +1,9 @@ -from typing import Union, Tuple, Sequence from abc import abstractmethod - import asyncore import socket +import sys +from typing import Union, Tuple, Sequence + class simple_producer: def __init__(self, data: str, buffer_size: int = ...) -> None: ... @@ -30,7 +31,6 @@ class async_chat (asyncore.dispatcher): def initiate_send(self) -> None: ... def discard_buffers(self) -> None: ... -import sys if sys.version_info < (3, 0, 0): class fifo: def __init__(self, list: Sequence[Union[str, simple_producer]] = ...) -> None: ... diff --git a/stdlib/2and3/asyncore.pyi b/stdlib/2and3/asyncore.pyi index 86af4a5f0..c7bf79397 100644 --- a/stdlib/2and3/asyncore.pyi +++ b/stdlib/2and3/asyncore.pyi @@ -1,6 +1,11 @@ from typing import Tuple, Union, Optional, Any, Dict, overload -import select, socket, sys, time, warnings, os +import os +import select +import socket +import sys +import time +import warnings from errno import (EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index 39b4be33e..ab16f7de3 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -1,17 +1,17 @@ # Stubs for logging.handlers (Python 2.4) -from typing import Any, Callable, Optional, Tuple, Union, overload -from logging import Handler, FileHandler, LogRecord import datetime +from logging import Handler, FileHandler, LogRecord +from socket import SocketType +import ssl +import sys +from typing import Any, Callable, Optional, Tuple, Union, overload if sys.version_info >= (3,): from queue import Queue else: from Queue import Queue -from socket import SocketType # TODO update socket stubs to add SocketKind SocketKind = int -import ssl -import sys class WatchedFileHandler(Handler): diff --git a/stdlib/2and3/mmap.pyi b/stdlib/2and3/mmap.pyi index 5050dac74..d0be9df5f 100644 --- a/stdlib/2and3/mmap.pyi +++ b/stdlib/2and3/mmap.pyi @@ -1,15 +1,14 @@ # Stubs for mmap -from typing import (Optional, Sequence, Union, Generic, TypeVar, overload, - Iterable, Container, Sized, Reversible) import sys +from types import TracebackType +from typing import (Optional, Sequence, Union, Generic, TypeVar, overload, + Iterable, Container, Sized, Reversible, Type) _T = TypeVar('_T', str, bytes) # TODO already in PEP, have to get added to mypy -from typing import Type -from types import TracebackType _C = TypeVar('_C') class _ContextManager(Generic[_C]): def __enter__(self) -> _C: ... diff --git a/stdlib/3.4/asyncio/futures.pyi b/stdlib/3.4/asyncio/futures.pyi index 1376cb331..b88009324 100644 --- a/stdlib/3.4/asyncio/futures.pyi +++ b/stdlib/3.4/asyncio/futures.pyi @@ -1,10 +1,5 @@ from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable from .events import AbstractEventLoop - -__all__ = ... # type: str - -_T = TypeVar('_T') - from concurrent.futures._base import ( Error as Error, ) @@ -12,6 +7,11 @@ from concurrent.futures import ( CancelledError as CancelledError, TimeoutError as TimeoutError, ) + +__all__ = ... # type: str + +_T = TypeVar('_T') + class InvalidStateError(Error): ... class _TracebackLogger: diff --git a/stdlib/3.4/asyncio/protocols.pyi b/stdlib/3.4/asyncio/protocols.pyi index d20313c23..91b7d94dd 100644 --- a/stdlib/3.4/asyncio/protocols.pyi +++ b/stdlib/3.4/asyncio/protocols.pyi @@ -1,8 +1,8 @@ +from asyncio import transports from typing import AnyStr __all__ = ... # type: str -from asyncio import transports class BaseProtocol: def connection_made(self, transport: transports.BaseTransport) -> None: ... diff --git a/stdlib/3.4/asyncio/queues.pyi b/stdlib/3.4/asyncio/queues.pyi index f08a545d5..dd1ffe600 100644 --- a/stdlib/3.4/asyncio/queues.pyi +++ b/stdlib/3.4/asyncio/queues.pyi @@ -1,10 +1,9 @@ -from typing import TypeVar, Generic - -__all__ = ... # type: str - from asyncio.events import AbstractEventLoop from .coroutines import coroutine from .futures import Future +from typing import TypeVar, Generic + +__all__ = ... # type: str class QueueEmpty(Exception): ... diff --git a/stdlib/3.4/asyncio/streams.pyi b/stdlib/3.4/asyncio/streams.pyi index a55b4e603..ed2030331 100644 --- a/stdlib/3.4/asyncio/streams.pyi +++ b/stdlib/3.4/asyncio/streams.pyi @@ -1,13 +1,14 @@ -from typing import Any, Callable, Generator, Iterable, Tuple - -ClientConnectedCallback = Callable[[Tuple[StreamReader, StreamWriter]], None] import socket +from typing import Any, Callable, Generator, Iterable, Tuple from . import coroutines from . import events from . import protocols from . import transports +ClientConnectedCallback = Callable[[Tuple[StreamReader, StreamWriter]], None] + + __all__ = ... # type: str class IncompleteReadError(EOFError): diff --git a/stdlib/3.4/asyncio/subprocess.pyi b/stdlib/3.4/asyncio/subprocess.pyi index 3dd52b9c6..2416f9235 100644 --- a/stdlib/3.4/asyncio/subprocess.pyi +++ b/stdlib/3.4/asyncio/subprocess.pyi @@ -1,13 +1,11 @@ -from typing import Any, AnyStr, Tuple, Union - -__all__ = ... # type: str - from asyncio import events from asyncio import protocols from asyncio import streams from asyncio import transports from asyncio.coroutines import coroutine +from typing import Any, AnyStr, Tuple, Union +__all__ = ... # type: str PIPE = ... # type: int STDOUT = ... # type: int diff --git a/stdlib/3.4/asyncio/tasks.pyi b/stdlib/3.4/asyncio/tasks.pyi index ebf0a7212..a33fd15d1 100644 --- a/stdlib/3.4/asyncio/tasks.pyi +++ b/stdlib/3.4/asyncio/tasks.pyi @@ -2,12 +2,11 @@ from typing import (Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic Coroutine, Generator, Iterable, Awaitable, overload, Sequence, Iterator, Optional) import concurrent.futures - -__all__ = ... # type: str - from .events import AbstractEventLoop from .futures import Future +__all__ = ... # type: str + _T = TypeVar('_T') FIRST_EXCEPTION = 'FIRST_EXCEPTION' diff --git a/stdlib/3/email/parser.pyi b/stdlib/3/email/parser.pyi index d878f1dd2..d0da73f69 100644 --- a/stdlib/3/email/parser.pyi +++ b/stdlib/3/email/parser.pyi @@ -1,11 +1,11 @@ # Stubs for email.parser (Python 3.4) -from typing import Callable, Optional, TextIO, BinaryIO import email.feedparser from email.message import Message +import sys +from typing import Callable, Optional, TextIO, BinaryIO if sys.version_info >= (3, 3): from email.policy import Policy -import sys FeedParser = email.feedparser.FeedParser BytesFeedParser = email.feedparser.BytesFeedParser diff --git a/stdlib/3/email/policy.pyi b/stdlib/3/email/policy.pyi index c34ee5829..8bd76e1d6 100644 --- a/stdlib/3/email/policy.pyi +++ b/stdlib/3/email/policy.pyi @@ -1,5 +1,6 @@ # Stubs for email.policy (Python 3.4) +from abc import abstractmethod from typing import Any, Optional, Tuple, Union, Callable import sys from email.message import Message @@ -7,7 +8,6 @@ from email.errors import MessageDefect from email.header import Header if sys.version_info >= (3, 4): from email.contentmanager import ContentManager -from abc import abstractmethod if sys.version_info >= (3, 3): diff --git a/stdlib/3/importlib/abc.pyi b/stdlib/3/importlib/abc.pyi index 75c335639..61f9472a6 100644 --- a/stdlib/3/importlib/abc.pyi +++ b/stdlib/3/importlib/abc.pyi @@ -1,16 +1,17 @@ from abc import ABCMeta, abstractmethod -if sys.version_info >= (3, 4): - from _importlib_modulespec import ModuleSpec import sys import types from typing import Any, Mapping, Optional, Sequence, Tuple, Union -_Path = Union[bytes, str] - # Loader is exported from this module, but for circular import reasons # exists in its own stub file (with ModuleSpec and ModuleType). from _importlib_modulespec import Loader as Loader # Exported +if sys.version_info >= (3, 4): + from _importlib_modulespec import ModuleSpec + +_Path = Union[bytes, str] + class Finder(metaclass=ABCMeta): ... # Technically this class defines the following method, but its subclasses # in this module violate its signature. Since this class is deprecated, it's diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 0a42e5a56..30e72954e 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -3,12 +3,13 @@ # based on http: //docs.python.org/3.2/library/os.html +from builtins import OSError as error +from io import TextIOWrapper as _TextIOWrapper +import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr, Optional, Generic, Set, Callable ) -import sys -from builtins import OSError as error from . import path # ----- os variables ----- @@ -323,7 +324,6 @@ def killpg(pgid: int, sig: int) -> None: ... # Unix only def nice(increment: int) -> int: ... # Unix only def plock(op: int) -> None: ... # Unix only ???op is int? -from io import TextIOWrapper as _TextIOWrapper class popen(_TextIOWrapper): # TODO 'b' modes or bytes command not accepted? def __init__(self, command: str, mode: str = ..., diff --git a/stdlib/3/platform.pyi b/stdlib/3/platform.pyi index 794d4c5e3..728e259fe 100644 --- a/stdlib/3/platform.pyi +++ b/stdlib/3/platform.pyi @@ -1,13 +1,12 @@ # Stubs for platform (Python 3.5) -from typing import Tuple, NamedTuple - from os import devnull as DEV_NULL +from os import popen +from typing import Tuple, NamedTuple def libc_ver(executable: str = ..., lib: str = ..., version: str = ..., chunksize: int = ...) -> Tuple[str, str]: ... def linux_distribution(distname: str = ..., version: str = ..., id: str = ..., supported_dists: Tuple[str, ...] = ..., full_distribution_name: bool = ...) -> Tuple[str, str, str]: ... def dist(distname: str = ..., version: str = ..., id: str = ..., supported_dists: Tuple[str, ...] = ...) -> Tuple[str, str, str]: ... -from os import popen def win32_ver(release: str = ..., version: str = ..., csd: str = ..., ptype: str = ...) -> Tuple[str, str, str, str]: ... def mac_ver(release: str = ..., versioninfo: Tuple[str, str, str] = ..., machine: str = ...) -> Tuple[str, Tuple[str, str, str], str]: ... def java_ver(release: str = ..., vendor: str = ..., vminfo: Tuple[str, str, str] = ..., osinfo: Tuple[str, str, str] = ...) -> Tuple[str, str, Tuple[str, str, str], Tuple[str, str, str]]: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index b927c14f8..17e33470a 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -9,6 +9,10 @@ from typing import ( Union, overload ) +# ModuleType is exported from this module, but for circular import +# reasons exists in its own stub file (with ModuleSpec and Loader). +from _importlib_modulespec import ModuleType as ModuleType # Exported + _T = TypeVar('_T') _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -107,10 +111,6 @@ class BuiltinFunctionType: def __call__(self, *args: Any, **kwargs: Any) -> Any: ... BuiltinMethodType = BuiltinFunctionType -# ModuleType is exported from this module, but for circular import -# reasons exists in its own stub file (with ModuleSpec and Loader). -from _importlib_modulespec import ModuleType as ModuleType # Exported - class TracebackType: tb_frame = ... # type: FrameType tb_lasti = ... # type: int diff --git a/third_party/2/simplejson/__init__.pyi b/third_party/2/simplejson/__init__.pyi index e3f6778c7..5f94eb969 100644 --- a/third_party/2/simplejson/__init__.pyi +++ b/third_party/2/simplejson/__init__.pyi @@ -1,10 +1,10 @@ from typing import Any, IO +from simplejson.scanner import JSONDecodeError +from simplejson.decoder import JSONDecoder +from simplejson.encoder import JSONEncoder, JSONEncoderForHTML + def dumps(obj: Any, *args: Any, **kwds: Any) -> str: ... def dump(obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ... def loads(s: str, **kwds: Any) -> Any: ... def load(fp: IO[str]) -> Any: ... - -from simplejson.scanner import JSONDecodeError -from simplejson.decoder import JSONDecoder -from simplejson.encoder import JSONEncoder, JSONEncoderForHTML diff --git a/third_party/2/six/__init__.pyi b/third_party/2/six/__init__.pyi index 1ee1f8bc9..7ed44fc62 100644 --- a/third_party/2/six/__init__.pyi +++ b/third_party/2/six/__init__.pyi @@ -2,14 +2,19 @@ from __future__ import print_function +import types from typing import ( Any, AnyStr, Callable, Iterable, Mapping, Optional, Pattern, Tuple, TypeVar, Union, overload, ValuesView, KeysView, ItemsView ) import typing - import unittest -import types + +# Exports +from __builtin__ import unichr as unichr +from StringIO import StringIO as StringIO, StringIO as BytesIO +from functools import wraps as wraps + _T = TypeVar('_T') _K = TypeVar('_K') @@ -62,12 +67,10 @@ def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ... def b(s: str) -> binary_type: ... def u(s: str) -> text_type: ... -from __builtin__ import unichr as unichr int2byte = chr def byte2int(bs: binary_type) -> int: ... def indexbytes(buf: binary_type, i: int) -> int: ... def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... -from StringIO import StringIO as StringIO, StringIO as BytesIO def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = ...) -> None: ... @overload @@ -82,8 +85,6 @@ def raise_from(value: BaseException, from_value: BaseException) -> None: ... print_ = print -from functools import wraps as wraps - def with_metaclass(meta: type, *bases: type) -> type: ... def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... def python_2_unicode_compatible(klass: _T) -> _T: ... diff --git a/third_party/2/sqlalchemy/sql/expression.pyi b/third_party/2/sqlalchemy/sql/expression.pyi index ab7e87447..48fc3b896 100644 --- a/third_party/2/sqlalchemy/sql/expression.pyi +++ b/third_party/2/sqlalchemy/sql/expression.pyi @@ -7,9 +7,6 @@ from . import base from . import selectable from . import dml -func = functions.func # type: functions._FunctionGenerator -modifier = functions.modifier # type: functions._FunctionGenerator - from .visitors import Visitable from .elements import ClauseElement, ColumnElement,\ @@ -28,6 +25,9 @@ from .selectable import Alias, Join, Select, Selectable, TableClause, \ subquery, HasPrefixes, HasSuffixes, Exists, ScalarSelect, TextAsFrom from .dml import Insert, Update, Delete, UpdateBase, ValuesBase +func = functions.func # type: functions._FunctionGenerator +modifier = functions.modifier # type: functions._FunctionGenerator + and_ = ... # type: Any or_ = ... # type: Any bindparam = ... # type: Any diff --git a/third_party/2and3/jinja2/utils.pyi b/third_party/2and3/jinja2/utils.pyi index 1f6d31bff..136829972 100644 --- a/third_party/2and3/jinja2/utils.pyi +++ b/third_party/2and3/jinja2/utils.pyi @@ -4,6 +4,8 @@ from typing import Any, Optional +from markupsafe import Markup, escape, soft_unicode + missing = ... # type: Any internal_code = ... # type: Any concat = ... # type: Any @@ -60,5 +62,3 @@ class Joiner: used = ... # type: bool def __init__(self, sep: str = ...) -> None: ... def __call__(self): ... - -from markupsafe import Markup, escape, soft_unicode diff --git a/third_party/3.6/click/core.pyi b/third_party/3.6/click/core.pyi index 66b5b840c..e775636ae 100644 --- a/third_party/3.6/click/core.pyi +++ b/third_party/3.6/click/core.pyi @@ -430,5 +430,5 @@ class Argument(Parameter): ) -> None: ... - -from click.types import ParamType # cyclic dependency +# cyclic dependency +from click.types import ParamType # noqa: E402 diff --git a/third_party/3/requests/packages/urllib3/connection.pyi b/third_party/3/requests/packages/urllib3/connection.pyi index 577bc8528..77e4c429d 100644 --- a/third_party/3/requests/packages/urllib3/connection.pyi +++ b/third_party/3/requests/packages/urllib3/connection.pyi @@ -3,6 +3,7 @@ from typing import Any from . import packages from http.client import HTTPConnection as _HTTPConnection +import ssl # from httplib import HTTPConnection as _HTTPConnection # python 2 from . import exceptions from .packages import ssl_match_hostname @@ -12,7 +13,6 @@ import http.client class DummyConnection: ... -import ssl BaseSSLError = ssl.SSLError ConnectionError = __builtins__.ConnectionError HTTPException = http.client.HTTPException diff --git a/third_party/3/six/__init__.pyi b/third_party/3/six/__init__.pyi index 6768fc124..5419d1559 100644 --- a/third_party/3/six/__init__.pyi +++ b/third_party/3/six/__init__.pyi @@ -19,10 +19,14 @@ from typing import ( ValuesView, overload, ) -import typing - -import unittest import types +import typing +import unittest + +# Exports +from io import StringIO as StringIO, BytesIO as BytesIO +from builtins import next as next +from functools import wraps as wraps _T = TypeVar('_T') _K = TypeVar('_K') @@ -45,9 +49,6 @@ MAXSIZE = ... # type: int # def add_move # def remove_move -from builtins import next as advance_iterator -next = advance_iterator - def callable(obj: object) -> bool: ... def get_unbound_function(unbound: types.FunctionType) -> types.FunctionType: ... @@ -80,7 +81,6 @@ def int2byte(i: int) -> bytes: ... def byte2int(bs: binary_type) -> int: ... def indexbytes(buf: binary_type, i: int) -> int: ... def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... -from io import StringIO as StringIO, BytesIO as BytesIO def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = None) -> None: ... @overload @@ -96,8 +96,6 @@ def raise_from(value: BaseException, from_value: BaseException) -> None: ... print_ = print -from functools import wraps as wraps - def with_metaclass(meta: type, *bases: type) -> type: ... def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... def python_2_unicode_compatible(klass: _T) -> _T: ...