]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Reformat codebase with isort
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Wed, 27 Jul 2022 01:33:08 +0000 (21:33 -0400)
committerRichard Si <63936253+ichard26@users.noreply.github.com>
Wed, 27 Jul 2022 21:19:28 +0000 (17:19 -0400)
30 files changed:
action/main.py
fuzz.py
gallery/gallery.py
scripts/migrate-black.py
setup.py
src/black/__init__.py
src/black/brackets.py
src/black/cache.py
src/black/comments.py
src/black/debug.py
src/black/files.py
src/black/handle_ipynb_magics.py
src/black/linegen.py
src/black/lines.py
src/black/mode.py
src/black/nodes.py
src/black/output.py
src/black/parsing.py
src/black/report.py
src/black/rusty.py
src/black/trans.py
src/blackd/__init__.py
src/blackd/middlewares.py
tests/optional.py
tests/test_black.py
tests/test_blackd.py
tests/test_format.py
tests/test_ipynb.py
tests/test_no_ipynb.py
tests/test_trans.py

index d14b10f421de32cdb58935a3d8ac60d8c5050578..cd920f5fe0ddd09c1d0dc5712795262f65dd1968 100644 (file)
@@ -2,7 +2,7 @@ import os
 import shlex
 import sys
 from pathlib import Path
-from subprocess import run, PIPE, STDOUT
+from subprocess import PIPE, STDOUT, run
 
 ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
 ENV_PATH = ACTION_PATH / ".black-env"
diff --git a/fuzz.py b/fuzz.py
index f5f655ea279fa2e569df1dce3e45479abe0b3bdb..83e02f4515294b0b79dd633d9898b4f90521aa28 100644 (file)
--- a/fuzz.py
+++ b/fuzz.py
@@ -8,7 +8,8 @@ a coverage-guided fuzzer I'm working on.
 import re
 
 import hypothesmith
-from hypothesis import HealthCheck, given, settings, strategies as st
+from hypothesis import HealthCheck, given, settings
+from hypothesis import strategies as st
 
 import black
 from blib2to3.pgen2.tokenize import TokenError
@@ -78,6 +79,7 @@ if __name__ == "__main__":
     # (if you want only bounded fuzzing, just use `pytest fuzz.py`)
     try:
         import sys
+
         import atheris
     except ImportError:
         pass
index be4d81dc4270be05a031c1c78df8a64b7b78a8aa..38e52e3479571559715fa9ec9122945f91b10dfe 100755 (executable)
@@ -10,15 +10,7 @@ from argparse import ArgumentParser, Namespace
 from concurrent.futures import ThreadPoolExecutor
 from functools import lru_cache, partial
 from pathlib import Path
-from typing import (
-    Generator,
-    List,
-    NamedTuple,
-    Optional,
-    Tuple,
-    Union,
-    cast,
-)
+from typing import Generator, List, NamedTuple, Optional, Tuple, Union, cast
 from urllib.request import urlopen, urlretrieve
 
 PYPI_INSTANCE = "https://pypi.org/pypi"
index 1183cb8a1047ce44ddcb8582e0a043b90201eaf2..63cc5096a939ebecbbc35d6dc2ed5981a86495b5 100755 (executable)
@@ -5,7 +5,7 @@
 import logging
 import os
 import sys
-from subprocess import check_output, run, Popen, PIPE
+from subprocess import PIPE, Popen, check_output, run
 
 
 def git(*args: str) -> str:
index 522a42a7ce216a3ba0cd723b91781cbc6f5526b2..3accdf433bc430f3f37e829dc6c2ede514107020 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,8 @@
 # Copyright (C) 2020 Łukasz Langa
-from setuptools import setup, find_packages
-import sys
 import os
+import sys
+
+from setuptools import find_packages, setup
 
 assert sys.version_info >= (3, 6, 2), "black requires Python 3.6.2+"
 from pathlib import Path  # noqa E402
index d2df1cbee7c27454cfdd137c246eeed30e42564a..2a5c750a5835562ddf5c743b01ab0cc58b4cb75c 100644 (file)
@@ -1,20 +1,20 @@
 import asyncio
-from json.decoder import JSONDecodeError
-import json
-from contextlib import contextmanager
-from datetime import datetime
-from enum import Enum
 import io
-from multiprocessing import Manager, freeze_support
+import json
 import os
-from pathlib import Path
-from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
 import platform
 import re
 import signal
 import sys
 import tokenize
 import traceback
+from contextlib import contextmanager
+from dataclasses import replace
+from datetime import datetime
+from enum import Enum
+from json.decoder import JSONDecodeError
+from multiprocessing import Manager, freeze_support
+from pathlib import Path
 from typing import (
     TYPE_CHECKING,
     Any,
@@ -34,48 +34,61 @@ from typing import (
 
 import click
 from click.core import ParameterSource
-from dataclasses import replace
 from mypy_extensions import mypyc_attr
+from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
 
-from black.const import DEFAULT_LINE_LENGTH, DEFAULT_INCLUDES, DEFAULT_EXCLUDES
-from black.const import STDIN_PLACEHOLDER
-from black.nodes import STARS, syms, is_simple_decorator_expression
-from black.nodes import is_string_token, is_number_token
-from black.lines import Line, EmptyLineTracker
-from black.linegen import transform_line, LineGenerator, LN
+from _black_version import version as __version__
+from black.cache import Cache, filter_cached, get_cache_info, read_cache, write_cache
 from black.comments import normalize_fmt_off
-from black.mode import FUTURE_FLAG_TO_FEATURE, Mode, TargetVersion
-from black.mode import Feature, supports_feature, VERSION_TO_FEATURES
-from black.cache import read_cache, write_cache, get_cache_info, filter_cached, Cache
-from black.concurrency import cancel, shutdown, maybe_install_uvloop
-from black.output import dump_to_file, ipynb_diff, diff, color_diff, out, err
-from black.report import Report, Changed, NothingChanged
+from black.concurrency import cancel, maybe_install_uvloop, shutdown
+from black.const import (
+    DEFAULT_EXCLUDES,
+    DEFAULT_INCLUDES,
+    DEFAULT_LINE_LENGTH,
+    STDIN_PLACEHOLDER,
+)
 from black.files import (
     find_project_root,
     find_pyproject_toml,
-    parse_pyproject_toml,
     find_user_pyproject_toml,
+    gen_python_files,
+    get_gitignore,
+    normalize_path_maybe_ignore,
+    parse_pyproject_toml,
+    wrap_stream_for_windows,
 )
-from black.files import gen_python_files, get_gitignore, normalize_path_maybe_ignore
-from black.files import wrap_stream_for_windows
-from black.parsing import InvalidInput  # noqa F401
-from black.parsing import lib2to3_parse, parse_ast, stringify_ast
 from black.handle_ipynb_magics import (
-    mask_cell,
-    unmask_cell,
-    remove_trailing_semicolon,
-    put_trailing_semicolon_back,
-    TRANSFORMED_MAGICS,
     PYTHON_CELL_MAGICS,
+    TRANSFORMED_MAGICS,
     jupyter_dependencies_are_installed,
+    mask_cell,
+    put_trailing_semicolon_back,
+    remove_trailing_semicolon,
+    unmask_cell,
 )
-
-
-# lib2to3 fork
-from blib2to3.pytree import Node, Leaf
+from black.linegen import LN, LineGenerator, transform_line
+from black.lines import EmptyLineTracker, Line
+from black.mode import (
+    FUTURE_FLAG_TO_FEATURE,
+    VERSION_TO_FEATURES,
+    Feature,
+    Mode,
+    TargetVersion,
+    supports_feature,
+)
+from black.nodes import (
+    STARS,
+    is_number_token,
+    is_simple_decorator_expression,
+    is_string_token,
+    syms,
+)
+from black.output import color_diff, diff, dump_to_file, err, ipynb_diff, out
+from black.parsing import InvalidInput  # noqa F401
+from black.parsing import lib2to3_parse, parse_ast, stringify_ast
+from black.report import Changed, NothingChanged, Report
 from blib2to3.pgen2 import token
-
-from _black_version import version as __version__
+from blib2to3.pytree import Leaf, Node
 
 if TYPE_CHECKING:
     from concurrent.futures import Executor
@@ -770,7 +783,7 @@ def reformat_many(
     workers: Optional[int],
 ) -> None:
     """Reformat multiple files using a ProcessPoolExecutor."""
-    from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor
+    from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
 
     executor: Executor
     worker_count = workers if workers is not None else DEFAULT_WORKERS
index c5ed4bf5b9f242752ad2ca7bf8902f853b64c4cf..3566f5b6c3757f3f12459e4c2f379b06da9e062c 100644 (file)
@@ -1,7 +1,7 @@
 """Builds on top of nodes.py to track brackets."""
 
-from dataclasses import dataclass, field
 import sys
+from dataclasses import dataclass, field
 from typing import Dict, Iterable, List, Optional, Tuple, Union
 
 if sys.version_info < (3, 8):
@@ -9,12 +9,20 @@ if sys.version_info < (3, 8):
 else:
     from typing import Final
 
-from blib2to3.pytree import Leaf, Node
+from black.nodes import (
+    BRACKET,
+    CLOSING_BRACKETS,
+    COMPARATORS,
+    LOGIC_OPERATORS,
+    MATH_OPERATORS,
+    OPENING_BRACKETS,
+    UNPACKING_PARENTS,
+    VARARGS_PARENTS,
+    is_vararg,
+    syms,
+)
 from blib2to3.pgen2 import token
-
-from black.nodes import syms, is_vararg, VARARGS_PARENTS, UNPACKING_PARENTS
-from black.nodes import BRACKET, OPENING_BRACKETS, CLOSING_BRACKETS
-from black.nodes import MATH_OPERATORS, COMPARATORS, LOGIC_OPERATORS
+from blib2to3.pytree import Leaf, Node
 
 # types
 LN = Union[Leaf, Node]
index 552c248d2ad0644f4855df562b9265ad6b649dd6..9455ff4477250b78e279040124dcc7215e2e351b 100644 (file)
@@ -2,16 +2,14 @@
 
 import os
 import pickle
-from pathlib import Path
 import tempfile
+from pathlib import Path
 from typing import Dict, Iterable, Set, Tuple
 
 from platformdirs import user_cache_dir
 
-from black.mode import Mode
-
 from _black_version import version as __version__
-
+from black.mode import Mode
 
 # types
 Timestamp = float
index 7069da165283aac12347a679707b8fc24fa8bea3..dc58934f9d313b22b0f3838ce856078fe1b644b9 100644 (file)
@@ -1,7 +1,7 @@
+import re
 import sys
 from dataclasses import dataclass
 from functools import lru_cache
-import re
 from typing import Iterator, List, Optional, Union
 
 if sys.version_info >= (3, 8):
@@ -9,11 +9,16 @@ if sys.version_info >= (3, 8):
 else:
     from typing_extensions import Final
 
-from blib2to3.pytree import Node, Leaf, type_repr
+from black.nodes import (
+    CLOSING_BRACKETS,
+    STANDALONE_COMMENT,
+    WHITESPACE,
+    container_of,
+    first_leaf_column,
+    preceding_leaf,
+)
 from blib2to3.pgen2 import token
-
-from black.nodes import first_leaf_column, preceding_leaf, container_of
-from black.nodes import CLOSING_BRACKETS, STANDALONE_COMMENT, WHITESPACE
+from blib2to3.pytree import Leaf, Node, type_repr
 
 # types
 LN = Union[Leaf, Node]
index 5143076ab35ff1c35a7b8a823e0c672078411b1f..150b44842dd1d9a0a852095aa4ee94e7e2e6b72d 100644 (file)
@@ -1,12 +1,11 @@
 from dataclasses import dataclass
 from typing import Iterator, TypeVar, Union
 
-from blib2to3.pytree import Node, Leaf, type_repr
-from blib2to3.pgen2 import token
-
 from black.nodes import Visitor
 from black.output import out
 from black.parsing import lib2to3_parse
+from blib2to3.pgen2 import token
+from blib2to3.pytree import Leaf, Node, type_repr
 
 LN = Union[Leaf, Node]
 T = TypeVar("T")
index 0382397e8a230f60f6a0b4cec6ee07bc80f9e281..17515d52b57b6427363f97526deffcbdbc6fdbb2 100644 (file)
@@ -1,9 +1,10 @@
-from functools import lru_cache
 import io
 import os
-from pathlib import Path
 import sys
+from functools import lru_cache
+from pathlib import Path
 from typing import (
+    TYPE_CHECKING,
     Any,
     Dict,
     Iterable,
@@ -14,7 +15,6 @@ from typing import (
     Sequence,
     Tuple,
     Union,
-    TYPE_CHECKING,
 )
 
 from mypy_extensions import mypyc_attr
@@ -30,9 +30,9 @@ if sys.version_info >= (3, 11):
 else:
     import tomli as tomllib
 
+from black.handle_ipynb_magics import jupyter_dependencies_are_installed
 from black.output import err
 from black.report import Report
-from black.handle_ipynb_magics import jupyter_dependencies_are_installed
 
 if TYPE_CHECKING:
     import colorama  # noqa: F401
index a0ed56baafcf86781b8c06da06922a52d2b5308a..693f1a68bd4701a361aefcc4c81f38481a7e48df 100644 (file)
@@ -1,22 +1,20 @@
 """Functions to process IPython magics with."""
 
-from functools import lru_cache
-import dataclasses
 import ast
-from typing import Dict, List, Tuple, Optional
-
+import collections
+import dataclasses
 import secrets
 import sys
-import collections
+from functools import lru_cache
+from typing import Dict, List, Optional, Tuple
 
 if sys.version_info >= (3, 10):
     from typing import TypeGuard
 else:
     from typing_extensions import TypeGuard
 
-from black.report import NothingChanged
 from black.output import out
-
+from black.report import NothingChanged
 
 TRANSFORMED_MAGICS = frozenset(
     (
@@ -90,11 +88,7 @@ def remove_trailing_semicolon(src: str) -> Tuple[str, bool]:
     Mirrors the logic in `quiet` from `IPython.core.displayhook`, but uses
     ``tokenize_rt`` so that round-tripping works fine.
     """
-    from tokenize_rt import (
-        src_to_tokens,
-        tokens_to_src,
-        reversed_enumerate,
-    )
+    from tokenize_rt import reversed_enumerate, src_to_tokens, tokens_to_src
 
     tokens = src_to_tokens(src)
     trailing_semicolon = False
@@ -118,7 +112,7 @@ def put_trailing_semicolon_back(src: str, has_trailing_semicolon: bool) -> str:
     """
     if not has_trailing_semicolon:
         return src
-    from tokenize_rt import src_to_tokens, tokens_to_src, reversed_enumerate
+    from tokenize_rt import reversed_enumerate, src_to_tokens, tokens_to_src
 
     tokens = src_to_tokens(src)
     for idx, token in reversed_enumerate(tokens):
index 8e8d41e239ae8e732e380ad08710c49f25156745..a2e41bf5912576f74ebdfbfcc29b3cc86ab07052 100644 (file)
@@ -1,38 +1,67 @@
 """
 Generating lines of code.
 """
-from functools import partial, wraps
 import sys
+from functools import partial, wraps
 from typing import Collection, Iterator, List, Optional, Set, Union, cast
 
-from black.nodes import WHITESPACE, RARROW, STATEMENT, STANDALONE_COMMENT
-from black.nodes import ASSIGNMENTS, OPENING_BRACKETS, CLOSING_BRACKETS
-from black.nodes import Visitor, syms, is_arith_like, ensure_visible
+from black.brackets import COMMA_PRIORITY, DOT_PRIORITY, max_delimiter_priority_in_atom
+from black.comments import FMT_OFF, generate_comments, list_comments
+from black.lines import (
+    Line,
+    append_leaves,
+    can_be_split,
+    can_omit_invisible_parens,
+    is_line_short_enough,
+    line_to_string,
+)
+from black.mode import Feature, Mode, Preview
 from black.nodes import (
+    ASSIGNMENTS,
+    CLOSING_BRACKETS,
+    OPENING_BRACKETS,
+    RARROW,
+    STANDALONE_COMMENT,
+    STATEMENT,
+    WHITESPACE,
+    Visitor,
+    ensure_visible,
+    is_arith_like,
+    is_atom_with_invisible_parens,
     is_docstring,
     is_empty_tuple,
-    is_one_tuple,
+    is_lpar_token,
+    is_multiline_string,
+    is_name_token,
     is_one_sequence_between,
+    is_one_tuple,
+    is_rpar_token,
+    is_stub_body,
+    is_stub_suite,
+    is_vararg,
+    is_walrus_assignment,
+    is_yield,
+    syms,
+    wrap_in_parentheses,
 )
-from black.nodes import is_name_token, is_lpar_token, is_rpar_token
-from black.nodes import is_walrus_assignment, is_yield, is_vararg, is_multiline_string
-from black.nodes import is_stub_suite, is_stub_body, is_atom_with_invisible_parens
-from black.nodes import wrap_in_parentheses
-from black.brackets import max_delimiter_priority_in_atom
-from black.brackets import DOT_PRIORITY, COMMA_PRIORITY
-from black.lines import Line, line_to_string, is_line_short_enough
-from black.lines import can_omit_invisible_parens, can_be_split, append_leaves
-from black.comments import generate_comments, list_comments, FMT_OFF
 from black.numerics import normalize_numeric_literal
-from black.strings import get_string_prefix, fix_docstring
-from black.strings import normalize_string_prefix, normalize_string_quotes
-from black.trans import Transformer, CannotTransform, StringMerger, StringSplitter
-from black.trans import StringParenWrapper, StringParenStripper, hug_power_op
-from black.mode import Mode, Feature, Preview
-
-from blib2to3.pytree import Node, Leaf
+from black.strings import (
+    fix_docstring,
+    get_string_prefix,
+    normalize_string_prefix,
+    normalize_string_quotes,
+)
+from black.trans import (
+    CannotTransform,
+    StringMerger,
+    StringParenStripper,
+    StringParenWrapper,
+    StringSplitter,
+    Transformer,
+    hug_power_op,
+)
 from blib2to3.pgen2 import token
-
+from blib2to3.pytree import Leaf, Node
 
 # types
 LeafID = int
index 8b591c324a5da6a27fc7fb7613f2900df2da9b7b..1ebc7808901d03335b48bf8d5e8fe0bb12d729a3 100644 (file)
@@ -1,6 +1,6 @@
-from dataclasses import dataclass, field
 import itertools
 import sys
+from dataclasses import dataclass, field
 from typing import (
     Callable,
     Dict,
@@ -13,16 +13,25 @@ from typing import (
     cast,
 )
 
-from blib2to3.pytree import Node, Leaf
-from blib2to3.pgen2 import token
-
-from black.brackets import BracketTracker, DOT_PRIORITY
+from black.brackets import DOT_PRIORITY, BracketTracker
 from black.mode import Mode, Preview
-from black.nodes import STANDALONE_COMMENT, TEST_DESCENDANTS
-from black.nodes import BRACKETS, OPENING_BRACKETS, CLOSING_BRACKETS
-from black.nodes import syms, whitespace, replace_child, child_towards
-from black.nodes import is_multiline_string, is_import, is_type_comment
-from black.nodes import is_one_sequence_between
+from black.nodes import (
+    BRACKETS,
+    CLOSING_BRACKETS,
+    OPENING_BRACKETS,
+    STANDALONE_COMMENT,
+    TEST_DESCENDANTS,
+    child_towards,
+    is_import,
+    is_multiline_string,
+    is_one_sequence_between,
+    is_type_comment,
+    replace_child,
+    syms,
+    whitespace,
+)
+from blib2to3.pgen2 import token
+from blib2to3.pytree import Leaf, Node
 
 # types
 T = TypeVar("T")
index b7359fab213d29bfe8fe0b1ecdebc67cade79f6a..32b65d16ca5a5f1e59543a3a278f4bff3e91f22b 100644 (file)
@@ -4,11 +4,10 @@ Mostly around Python language feature support per version and Black configuratio
 chosen by the user.
 """
 
-from hashlib import sha256
 import sys
-
 from dataclasses import dataclass, field
 from enum import Enum, auto
+from hashlib import sha256
 from operator import attrgetter
 from typing import Dict, Set
 from warnings import warn
index 12f24b966874e79931c0f8bafa8d86275c285d1c..8f341ab35d63e6e9212489bc1f4bdaf8de04909e 100644 (file)
@@ -3,16 +3,7 @@ blib2to3 Node/Leaf transformation-related utility functions.
 """
 
 import sys
-from typing import (
-    Generic,
-    Iterator,
-    List,
-    Optional,
-    Set,
-    Tuple,
-    TypeVar,
-    Union,
-)
+from typing import Generic, Iterator, List, Optional, Set, Tuple, TypeVar, Union
 
 if sys.version_info >= (3, 8):
     from typing import Final
@@ -25,14 +16,11 @@ else:
 
 from mypy_extensions import mypyc_attr
 
-# lib2to3 fork
-from blib2to3.pytree import Node, Leaf, type_repr, NL
-from blib2to3 import pygram
-from blib2to3.pgen2 import token
-
 from black.cache import CACHE_DIR
 from black.strings import has_triple_quotes
-
+from blib2to3 import pygram
+from blib2to3.pgen2 import token
+from blib2to3.pytree import NL, Leaf, Node, type_repr
 
 pygram.initialize(CACHE_DIR)
 syms: Final = pygram.python_symbols
index 9561d4b57d2a9b522de86a26a90d23413f09bd14..f4c17f28ea418d363f9b388e3770c208ca26b1b1 100644 (file)
@@ -4,11 +4,11 @@ The double calls are for patching purposes in tests.
 """
 
 import json
-from typing import Any, Optional
-from mypy_extensions import mypyc_attr
 import tempfile
+from typing import Any, Optional
 
 from click import echo, style
+from mypy_extensions import mypyc_attr
 
 
 @mypyc_attr(patchable=True)
index d1ad7d2c671a605d5a8745f39f47de355ae22cae..64c0b1e30183fda1e711c27bda48264cba4e000d 100644 (file)
@@ -11,16 +11,14 @@ if sys.version_info < (3, 8):
 else:
     from typing import Final
 
-# lib2to3 fork
-from blib2to3.pytree import Node, Leaf
+from black.mode import Feature, TargetVersion, supports_feature
+from black.nodes import syms
 from blib2to3 import pygram
 from blib2to3.pgen2 import driver
 from blib2to3.pgen2.grammar import Grammar
 from blib2to3.pgen2.parse import ParseError
 from blib2to3.pgen2.tokenize import TokenError
-
-from black.mode import TargetVersion, Feature, supports_feature
-from black.nodes import syms
+from blib2to3.pytree import Leaf, Node
 
 ast3: Any
 
index 43b942c9e3c809f57796f9c37da9921fffcf728b..a507671e4c0286d9ae0c7b41f86ce802da02c63c 100644 (file)
@@ -7,7 +7,7 @@ from pathlib import Path
 
 from click import style
 
-from black.output import out, err
+from black.output import err, out
 
 
 class Changed(Enum):
index 822e3d7858a077425bc83ade95fe74aa2eac2d59..84a80b5a2c223c188b94633d6298e6208441cf5b 100644 (file)
@@ -4,7 +4,6 @@ See https://doc.rust-lang.org/book/ch09-00-error-handling.html.
 """
 from typing import Generic, TypeVar, Union
 
-
 T = TypeVar("T")
 E = TypeVar("E", bound=Exception)
 
index 28d9250adc1fe78d7e788b2d6fd382d00d42073b..dc9c5520d5bdfcaf7e56bd8c93fae537e779f0ed 100644 (file)
@@ -1,10 +1,11 @@
 """
 String transformers that can split and merge strings.
 """
+import re
+import sys
 from abc import ABC, abstractmethod
 from collections import defaultdict
 from dataclasses import dataclass
-import re
 from typing import (
     Any,
     Callable,
@@ -21,29 +22,38 @@ from typing import (
     TypeVar,
     Union,
 )
-import sys
 
 if sys.version_info < (3, 8):
-    from typing_extensions import Literal, Final
+    from typing_extensions import Final, Literal
 else:
     from typing import Literal, Final
 
 from mypy_extensions import trait
 
-from black.rusty import Result, Ok, Err
-
-from black.mode import Feature
-from black.nodes import syms, replace_child, parent_type
-from black.nodes import is_empty_par, is_empty_lpar, is_empty_rpar
-from black.nodes import OPENING_BRACKETS, CLOSING_BRACKETS, STANDALONE_COMMENT
-from black.lines import Line, append_leaves
 from black.brackets import BracketMatchError
 from black.comments import contains_pragma_comment
-from black.strings import has_triple_quotes, get_string_prefix, assert_is_leaf_string
-from black.strings import normalize_string_quotes
-
-from blib2to3.pytree import Leaf, Node
+from black.lines import Line, append_leaves
+from black.mode import Feature
+from black.nodes import (
+    CLOSING_BRACKETS,
+    OPENING_BRACKETS,
+    STANDALONE_COMMENT,
+    is_empty_lpar,
+    is_empty_par,
+    is_empty_rpar,
+    parent_type,
+    replace_child,
+    syms,
+)
+from black.rusty import Err, Ok, Result
+from black.strings import (
+    assert_is_leaf_string,
+    get_string_prefix,
+    has_triple_quotes,
+    normalize_string_quotes,
+)
 from blib2to3.pgen2 import token
+from blib2to3.pytree import Leaf, Node
 
 
 class CannotTransform(Exception):
index 0463f169e196518eb7b9d611a321ea4abc9a9216..a6de79fbeaa4c98300a78442077255d77ba882f0 100644 (file)
@@ -8,6 +8,7 @@ from typing import Set, Tuple
 
 try:
     from aiohttp import web
+
     from .middlewares import cors
 except ImportError as ie:
     raise ImportError(
@@ -16,11 +17,11 @@ except ImportError as ie:
         + "to obtain aiohttp_cors: `pip install black[d]`"
     ) from None
 
-import black
-from black.concurrency import maybe_install_uvloop
 import click
 
+import black
 from _black_version import version as __version__
+from black.concurrency import maybe_install_uvloop
 
 # This is used internally by tests to shut down the server prematurely
 _stop_signal = asyncio.Event()
index 97994ecc1dff81df44d81076534c9886e527bf1f..7abde525bfdc0bf3297ac3bee67e08f284b59d18 100644 (file)
@@ -1,7 +1,8 @@
-from typing import Iterable, Awaitable, Callable
-from aiohttp.web_response import StreamResponse
-from aiohttp.web_request import Request
+from typing import Awaitable, Callable, Iterable
+
 from aiohttp.web_middlewares import middleware
+from aiohttp.web_request import Request
+from aiohttp.web_response import StreamResponse
 
 Handler = Callable[[Request], Awaitable[StreamResponse]]
 Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]
index a4e9441ef1c98f9bfcfcc0776063fcf82e87dc35..853ecaa2a43d5424492fc3c741975c0c05430e32 100644 (file)
@@ -14,11 +14,11 @@ Specifying the name of the default behavior in `--run-optional=` is harmless.
 Adapted from https://pypi.org/project/pytest-optional-tests/, (c) 2019 Reece Hart
 """
 
-from functools import lru_cache
 import itertools
 import logging
 import re
-from typing import FrozenSet, List, Set, TYPE_CHECKING
+from functools import lru_cache
+from typing import TYPE_CHECKING, FrozenSet, List, Set
 
 import pytest
 
@@ -32,8 +32,8 @@ log = logging.getLogger(__name__)
 
 
 if TYPE_CHECKING:
-    from _pytest.config.argparsing import Parser
     from _pytest.config import Config
+    from _pytest.config.argparsing import Parser
     from _pytest.mark.structures import MarkDecorator
     from _pytest.nodes import Node
 
index 8adcaed5ef8a78665d63adbe138586ba00d142fb..bb7784d547856382f17423ecf60ad01d18b55854 100644 (file)
@@ -6,6 +6,7 @@ import io
 import logging
 import multiprocessing
 import os
+import re
 import sys
 import types
 import unittest
@@ -31,7 +32,6 @@ from unittest.mock import MagicMock, patch
 
 import click
 import pytest
-import re
 from click import unstyle
 from click.testing import CliRunner
 from pathspec import PathSpec
@@ -59,8 +59,8 @@ from tests.util import (
     dump_to_stderr,
     ff,
     fs,
-    read_data,
     get_case_path,
+    read_data,
     read_data_from_file,
 )
 
index 75d756705be7847a4371e9c09c3c0fc088e5101a..18b2c98ac1f93ccadc57254584b93d72190cabe7 100644 (file)
@@ -2,15 +2,16 @@ import re
 from typing import Any
 from unittest.mock import patch
 
-from click.testing import CliRunner
 import pytest
+from click.testing import CliRunner
 
-from tests.util import read_data, DETERMINISTIC_HEADER
+from tests.util import DETERMINISTIC_HEADER, read_data
 
 try:
-    import blackd
-    from aiohttp.test_utils import AioHTTPTestCase
     from aiohttp import web
+    from aiohttp.test_utils import AioHTTPTestCase
+
+    import blackd
 except ImportError as e:
     raise RuntimeError("Please install Black with the 'd' extra") from e
 
index 7a099fb9f3343350cfaa33773f84984cf783a0b5..3645934721f0248278d08e14c6386cbd2bcde86d 100644 (file)
@@ -8,10 +8,10 @@ import black
 from tests.util import (
     DEFAULT_MODE,
     PY36_VERSIONS,
+    all_data_cases,
     assert_format,
     dump_to_stderr,
     read_data,
-    all_data_cases,
 )
 
 
index e1d7dd88dcba7398af62e8ded7006d760dbf365a..7aa2e91dd0010ba7a8097c677506b21265bf850a 100644 (file)
@@ -1,23 +1,24 @@
 import contextlib
-from dataclasses import replace
 import pathlib
 import re
 from contextlib import ExitStack as does_not_raise
+from dataclasses import replace
 from typing import ContextManager
 
+import pytest
+from _pytest.monkeypatch import MonkeyPatch
 from click.testing import CliRunner
-from black.handle_ipynb_magics import jupyter_dependencies_are_installed
+
 from black import (
-    main,
+    Mode,
     NothingChanged,
     format_cell,
     format_file_contents,
     format_file_in_place,
+    main,
 )
-import pytest
-from black import Mode
-from _pytest.monkeypatch import MonkeyPatch
-from tests.util import DATA_DIR, read_jupyter_notebook, get_case_path
+from black.handle_ipynb_magics import jupyter_dependencies_are_installed
+from tests.util import DATA_DIR, get_case_path, read_jupyter_notebook
 
 with contextlib.suppress(ModuleNotFoundError):
     import IPython
index a3c897760fb874a8909a78f2e0c3a665893544ff..3e0b1593bf06421a409f6eb591b3e954a0fdaf39 100644 (file)
@@ -1,10 +1,11 @@
-import pytest
 import pathlib
 
-from tests.util import get_case_path
-from black import main, jupyter_dependencies_are_installed
+import pytest
 from click.testing import CliRunner
 
+from black import jupyter_dependencies_are_installed, main
+from tests.util import get_case_path
+
 pytestmark = pytest.mark.no_jupyter
 
 runner = CliRunner()
index a1666a9c1669b7631db79aeb94478ed0757b0d1a..dce8a939677657549fa5abb35b19e0546d862893 100644 (file)
@@ -1,4 +1,5 @@
 from typing import List, Tuple
+
 from black.trans import iter_fexpr_spans