Upgrade to isort 5 (#4323)

This now also reformats imports not at the top of files.
This commit is contained in:
Sebastian Rittau
2020-07-16 16:01:57 +02:00
committed by GitHub
parent 1e0e40f61c
commit 5e76f51930
20 changed files with 67 additions and 55 deletions

View File

@@ -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

View File

@@ -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",
]

View File

@@ -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

View File

@@ -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]

View File

@@ -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:

View File

@@ -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]

View File

@@ -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

View File

@@ -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,

View File

@@ -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):

View File

@@ -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")

View File

@@ -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

View File

@@ -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]

View File

@@ -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")

View File

@@ -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

View File

@@ -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]

View File

@@ -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): ...

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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): ...

View File

@@ -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 = ...