diff --git a/.travis.yml b/.travis.yml index 02794ae56e69..f49c35724eb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,4 +34,4 @@ jobs: script: black --check --diff stdlib third_party - name: "isort" install: pip install $(grep isort requirements-tests-py3.txt) - script: isort --check-only --diff --recursive stdlib third_party + script: isort --check-only --diff stdlib third_party diff --git a/pyproject.toml b/pyproject.toml index c9b6b9b0d557..4cf76d7a2658 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,38 @@ multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true +ensure_newline_before_comments = true combine_as_imports = true line_length = 130 -default_section = "THIRDPARTY" -known_standard_library = ["typing_extensions", "_typeshed", "_compression", "_markupbase", "opcode"] +extra_standard_library = [ + "typing_extensions", + "_typeshed", + # Extra modules not recognized by isort + "_compression", + "_csv", + "_curses", + "_markupbase", + "_random", + "_weakrefset", + "genericpath", + "opcode", + "pyexpat", + # Python 2 modules + "__builtin__", + "cookielib", + "cStringIO", + "httplib", + "mimetools", + "rfc822", + "thread", + "urllib2", + "urlparse", + "BaseHTTPServer", + "Queue", + "SimpleHTTPServer", + "SocketServer", + "StringIO", + "UserDict", + "UserList", + "UserString", +] diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index f8568f8330d9..72c5cf0b51ab 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -1,8 +1,8 @@ git+https://github.com/python/mypy.git@master typed-ast>=1.0.4 black==19.10b0 -flake8==3.8.2 +flake8==3.8.3 flake8-bugbear==20.1.4 flake8-pyi==20.5.0 -isort[pyproject]==4.3.21 +isort[pyproject]==5.1.1 pytype>=2020.06.26 diff --git a/stdlib/2and3/_dummy_threading.pyi b/stdlib/2and3/_dummy_threading.pyi index 0ac579592ca7..c20067545d43 100644 --- a/stdlib/2and3/_dummy_threading.pyi +++ b/stdlib/2and3/_dummy_threading.pyi @@ -155,7 +155,7 @@ class Event: def wait(self, timeout: Optional[float] = ...) -> bool: ... if sys.version_info >= (3, 8): - from _thread import _ExceptHookArgs as ExceptHookArgs, ExceptHookArgs as _ExceptHookArgs # don't ask + from _thread import ExceptHookArgs as _ExceptHookArgs, _ExceptHookArgs as ExceptHookArgs # don't ask excepthook: Callable[[_ExceptHookArgs], Any] diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index bade71cf1138..8c0ca610f6ed 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -7,7 +7,7 @@ from socket import SocketType from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload if sys.version_info >= (3, 7): - from queue import SimpleQueue, Queue + from queue import Queue, SimpleQueue elif sys.version_info >= (3,): from queue import Queue else: diff --git a/stdlib/2and3/threading.pyi b/stdlib/2and3/threading.pyi index 0ac579592ca7..c20067545d43 100644 --- a/stdlib/2and3/threading.pyi +++ b/stdlib/2and3/threading.pyi @@ -155,7 +155,7 @@ class Event: def wait(self, timeout: Optional[float] = ...) -> bool: ... if sys.version_info >= (3, 8): - from _thread import _ExceptHookArgs as ExceptHookArgs, ExceptHookArgs as _ExceptHookArgs # don't ask + from _thread import ExceptHookArgs as _ExceptHookArgs, _ExceptHookArgs as ExceptHookArgs # don't ask excepthook: Callable[[_ExceptHookArgs], Any] diff --git a/stdlib/2and3/wsgiref/simple_server.pyi b/stdlib/2and3/wsgiref/simple_server.pyi index 0421098c39d4..66cd94fa7f7f 100644 --- a/stdlib/2and3/wsgiref/simple_server.pyi +++ b/stdlib/2and3/wsgiref/simple_server.pyi @@ -7,7 +7,7 @@ from .types import ErrorStream, StartResponse, WSGIApplication, WSGIEnvironment if sys.version_info < (3,): from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer else: - from http.server import HTTPServer, BaseHTTPRequestHandler + from http.server import BaseHTTPRequestHandler, HTTPServer server_version: str # undocumented sys_version: str # undocumented diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index d4f9157c99a4..24d59c938776 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -89,13 +89,10 @@ else: from asyncio.events import SendfileNotAvailableError as SendfileNotAvailableError from asyncio.futures import ( CancelledError as CancelledError, - TimeoutError as TimeoutError, InvalidStateError as InvalidStateError, + TimeoutError as TimeoutError, ) - from asyncio.streams import ( - IncompleteReadError as IncompleteReadError, - LimitOverrunError as LimitOverrunError, - ) + from asyncio.streams import IncompleteReadError as IncompleteReadError, LimitOverrunError as LimitOverrunError if sys.version_info >= (3, 7): from asyncio.protocols import BufferedProtocol as BufferedProtocol @@ -104,11 +101,7 @@ if sys.version_info >= (3, 7): from asyncio.runners import run as run if sys.version_info >= (3, 7): - from asyncio.tasks import ( - all_tasks as all_tasks, - create_task as create_task, - current_task as current_task, - ) + from asyncio.tasks import all_tasks as all_tasks, create_task as create_task, current_task as current_task if sys.version_info >= (3, 9): from asyncio.threads import to_thread as to_thread @@ -117,10 +110,8 @@ if sys.platform == "win32": from asyncio.windows_events import * if sys.platform != "win32": - from asyncio.streams import ( - open_unix_connection as open_unix_connection, - start_unix_server as start_unix_server, - ) + from asyncio.streams import open_unix_connection as open_unix_connection, start_unix_server as start_unix_server + from .unix_events import ( AbstractChildWatcher as AbstractChildWatcher, FastChildWatcher as FastChildWatcher, diff --git a/stdlib/3/asyncio/futures.pyi b/stdlib/3/asyncio/futures.pyi index a92fb90cd522..1b4bfb2b476f 100644 --- a/stdlib/3/asyncio/futures.pyi +++ b/stdlib/3/asyncio/futures.pyi @@ -5,8 +5,7 @@ from typing import Any, Awaitable, Callable, Generator, Iterable, List, Optional from .events import AbstractEventLoop if sys.version_info < (3, 8): - from concurrent.futures import CancelledError as CancelledError - from concurrent.futures import TimeoutError as TimeoutError + from concurrent.futures import CancelledError as CancelledError, TimeoutError as TimeoutError class InvalidStateError(Error): ... if sys.version_info >= (3, 7): diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 945c78867e8b..7790113c8710 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -41,10 +41,7 @@ from typing import ( from . import abc if sys.version_info >= (3, 6): - from typing import ( - Collection as Collection, - AsyncGenerator as AsyncGenerator, - ) + from typing import AsyncGenerator as AsyncGenerator, Collection as Collection _S = TypeVar("_S") _T = TypeVar("_T") diff --git a/stdlib/3/collections/abc.pyi b/stdlib/3/collections/abc.pyi index 24a10b9d42aa..2873cd3d14bb 100644 --- a/stdlib/3/collections/abc.pyi +++ b/stdlib/3/collections/abc.pyi @@ -29,8 +29,4 @@ from . import ( ) if sys.version_info >= (3, 6): - from . import ( - Collection as Collection, - Reversible as Reversible, - AsyncGenerator as AsyncGenerator, - ) + from . import AsyncGenerator as AsyncGenerator, Collection as Collection, Reversible as Reversible diff --git a/stdlib/3/importlib/resources.pyi b/stdlib/3/importlib/resources.pyi index 6f103fb0946e..be8d49ec3193 100644 --- a/stdlib/3/importlib/resources.pyi +++ b/stdlib/3/importlib/resources.pyi @@ -3,10 +3,9 @@ import sys # This is a >=3.7 module, so we conditionally include its source. if sys.version_info >= (3, 7): import os - from pathlib import Path from types import ModuleType - from typing import ContextManager, Iterator, Union, BinaryIO, TextIO + from typing import BinaryIO, ContextManager, Iterator, TextIO, Union Package = Union[str, ModuleType] Resource = Union[str, os.PathLike] diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index 13a41f526c9a..1ddfcdcad7b9 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -25,7 +25,7 @@ from typing import ( from .context import BaseContext if sys.version_info >= (3, 8): - from .shared_memory import ShareableList, SharedMemory, _SLT + from .shared_memory import _SLT, ShareableList, SharedMemory _T = TypeVar("_T") _KT = TypeVar("_KT") diff --git a/stdlib/3/re.pyi b/stdlib/3/re.pyi index 8058636655d4..0fa68c4b9c01 100644 --- a/stdlib/3/re.pyi +++ b/stdlib/3/re.pyi @@ -10,9 +10,9 @@ from typing import Any, AnyStr, Callable, Iterator, List, Optional, Tuple, Union # ----- re variables and constants ----- if sys.version_info >= (3, 7): - from typing import Pattern as Pattern, Match as Match + from typing import Match as Match, Pattern as Pattern else: - from typing import Pattern, Match + from typing import Match, Pattern if sys.version_info >= (3, 6): import enum diff --git a/third_party/2and3/decorator.pyi b/third_party/2and3/decorator.pyi index 618083d1c540..0d6238e7574f 100644 --- a/third_party/2and3/decorator.pyi +++ b/third_party/2and3/decorator.pyi @@ -8,8 +8,7 @@ _T = TypeVar("_T") def get_init(cls): ... if sys.version_info >= (3,): - from inspect import iscoroutinefunction as iscoroutinefunction - from inspect import getfullargspec as getfullargspec + from inspect import getfullargspec as getfullargspec, iscoroutinefunction as iscoroutinefunction else: class FullArgSpec(NamedTuple): args: List[str] diff --git a/third_party/2and3/jinja2/environment.pyi b/third_party/2and3/jinja2/environment.pyi index 673735ede5d6..58a3d317ba7a 100644 --- a/third_party/2and3/jinja2/environment.pyi +++ b/third_party/2and3/jinja2/environment.pyi @@ -6,7 +6,7 @@ from .loaders import BaseLoader from .runtime import Context, Undefined if sys.version_info >= (3, 6): - from typing import Awaitable, AsyncIterator + from typing import AsyncIterator, Awaitable def get_spontaneous_environment(*args): ... def create_cache(size): ... diff --git a/third_party/2and3/requests/packages/urllib3/connection.pyi b/third_party/2and3/requests/packages/urllib3/connection.pyi index 511164769428..0a7e25317e70 100644 --- a/third_party/2and3/requests/packages/urllib3/connection.pyi +++ b/third_party/2and3/requests/packages/urllib3/connection.pyi @@ -9,14 +9,12 @@ from .packages import ssl_match_hostname from .util import ssl_ if sys.version_info < (3, 0): - from httplib import HTTPConnection as _HTTPConnection - from httplib import HTTPException as HTTPException + from httplib import HTTPConnection as _HTTPConnection, HTTPException as HTTPException class ConnectionError(Exception): ... else: - from http.client import HTTPConnection as _HTTPConnection - from http.client import HTTPException as HTTPException from builtins import ConnectionError as ConnectionError + from http.client import HTTPConnection as _HTTPConnection, HTTPException as HTTPException class DummyConnection: ... diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index 9afdd5a236aa..3342c06af526 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -70,11 +70,13 @@ if sys.version_info >= (3, 3): from typing import ChainMap as ChainMap if sys.version_info >= (3, 5): - from typing import AsyncIterable as AsyncIterable - from typing import AsyncIterator as AsyncIterator - from typing import AsyncContextManager as AsyncContextManager - from typing import Awaitable as Awaitable - from typing import Coroutine as Coroutine + from typing import ( + AsyncContextManager as AsyncContextManager, + AsyncIterable as AsyncIterable, + AsyncIterator as AsyncIterator, + Awaitable as Awaitable, + Coroutine as Coroutine, + ) if sys.version_info >= (3, 6): from typing import AsyncGenerator as AsyncGenerator diff --git a/third_party/2and3/werkzeug/serving.pyi b/third_party/2and3/werkzeug/serving.pyi index 2bd4590eefc6..d75a3956731a 100644 --- a/third_party/2and3/werkzeug/serving.pyi +++ b/third_party/2and3/werkzeug/serving.pyi @@ -2,11 +2,11 @@ import sys from typing import Any, Optional if sys.version_info < (3,): + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from SocketServer import ThreadingMixIn - from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler else: + from http.server import BaseHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn - from http.server import HTTPServer, BaseHTTPRequestHandler if sys.platform == "win32": class ForkingMixIn(object): ... diff --git a/third_party/2and3/werkzeug/test.pyi b/third_party/2and3/werkzeug/test.pyi index c8425b8ceacc..40d074fece37 100644 --- a/third_party/2and3/werkzeug/test.pyi +++ b/third_party/2and3/werkzeug/test.pyi @@ -4,11 +4,11 @@ from typing import Any, Generic, Optional, Text, Tuple, Type, TypeVar, overload from typing_extensions import Literal if sys.version_info < (3,): - from urllib2 import Request as U2Request from cookielib import CookieJar + from urllib2 import Request as U2Request else: - from urllib.request import Request as U2Request from http.cookiejar import CookieJar + from urllib.request import Request as U2Request def stream_encode_multipart( values, use_tempfile: int = ..., threshold=..., boundary: Optional[Any] = ..., charset: Text = ...