Reformat codebase with isort

This commit is contained in:
Richard Si 2022-07-26 21:33:08 -04:00
parent e0a780a505
commit 44d5da00b5
30 changed files with 237 additions and 187 deletions

View File

@ -2,7 +2,7 @@
import shlex import shlex
import sys import sys
from pathlib import Path from pathlib import Path
from subprocess import run, PIPE, STDOUT from subprocess import PIPE, STDOUT, run
ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"]) ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
ENV_PATH = ACTION_PATH / ".black-env" ENV_PATH = ACTION_PATH / ".black-env"

View File

@ -8,7 +8,8 @@
import re import re
import hypothesmith 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 import black
from blib2to3.pgen2.tokenize import TokenError from blib2to3.pgen2.tokenize import TokenError
@ -78,6 +79,7 @@ def test_idempotent_any_syntatically_valid_python(
# (if you want only bounded fuzzing, just use `pytest fuzz.py`) # (if you want only bounded fuzzing, just use `pytest fuzz.py`)
try: try:
import sys import sys
import atheris import atheris
except ImportError: except ImportError:
pass pass

View File

@ -10,15 +10,7 @@
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from functools import lru_cache, partial from functools import lru_cache, partial
from pathlib import Path from pathlib import Path
from typing import ( from typing import Generator, List, NamedTuple, Optional, Tuple, Union, cast
Generator,
List,
NamedTuple,
Optional,
Tuple,
Union,
cast,
)
from urllib.request import urlopen, urlretrieve from urllib.request import urlopen, urlretrieve
PYPI_INSTANCE = "https://pypi.org/pypi" PYPI_INSTANCE = "https://pypi.org/pypi"

View File

@ -5,7 +5,7 @@
import logging import logging
import os import os
import sys import sys
from subprocess import check_output, run, Popen, PIPE from subprocess import PIPE, Popen, check_output, run
def git(*args: str) -> str: def git(*args: str) -> str:

View File

@ -1,7 +1,8 @@
# Copyright (C) 2020 Łukasz Langa # Copyright (C) 2020 Łukasz Langa
from setuptools import setup, find_packages
import sys
import os import os
import sys
from setuptools import find_packages, setup
assert sys.version_info >= (3, 6, 2), "black requires Python 3.6.2+" assert sys.version_info >= (3, 6, 2), "black requires Python 3.6.2+"
from pathlib import Path # noqa E402 from pathlib import Path # noqa E402

View File

@ -1,20 +1,20 @@
import asyncio import asyncio
from json.decoder import JSONDecodeError
import json
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
import io import io
from multiprocessing import Manager, freeze_support import json
import os import os
from pathlib import Path
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
import platform import platform
import re import re
import signal import signal
import sys import sys
import tokenize import tokenize
import traceback 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 ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
@ -34,48 +34,61 @@
import click import click
from click.core import ParameterSource from click.core import ParameterSource
from dataclasses import replace
from mypy_extensions import mypyc_attr 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_version import version as __version__
from black.const import STDIN_PLACEHOLDER from black.cache import Cache, filter_cached, get_cache_info, read_cache, write_cache
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.comments import normalize_fmt_off from black.comments import normalize_fmt_off
from black.mode import FUTURE_FLAG_TO_FEATURE, Mode, TargetVersion from black.concurrency import cancel, maybe_install_uvloop, shutdown
from black.mode import Feature, supports_feature, VERSION_TO_FEATURES from black.const import (
from black.cache import read_cache, write_cache, get_cache_info, filter_cached, Cache DEFAULT_EXCLUDES,
from black.concurrency import cancel, shutdown, maybe_install_uvloop DEFAULT_INCLUDES,
from black.output import dump_to_file, ipynb_diff, diff, color_diff, out, err DEFAULT_LINE_LENGTH,
from black.report import Report, Changed, NothingChanged STDIN_PLACEHOLDER,
)
from black.files import ( from black.files import (
find_project_root, find_project_root,
find_pyproject_toml, find_pyproject_toml,
parse_pyproject_toml,
find_user_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.handle_ipynb_magics import (
from black.files import wrap_stream_for_windows PYTHON_CELL_MAGICS,
TRANSFORMED_MAGICS,
jupyter_dependencies_are_installed,
mask_cell,
put_trailing_semicolon_back,
remove_trailing_semicolon,
unmask_cell,
)
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 InvalidInput # noqa F401
from black.parsing import lib2to3_parse, parse_ast, stringify_ast from black.parsing import lib2to3_parse, parse_ast, stringify_ast
from black.handle_ipynb_magics import ( from black.report import Changed, NothingChanged, Report
mask_cell,
unmask_cell,
remove_trailing_semicolon,
put_trailing_semicolon_back,
TRANSFORMED_MAGICS,
PYTHON_CELL_MAGICS,
jupyter_dependencies_are_installed,
)
# lib2to3 fork
from blib2to3.pytree import Node, Leaf
from blib2to3.pgen2 import token from blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node
from _black_version import version as __version__
if TYPE_CHECKING: if TYPE_CHECKING:
from concurrent.futures import Executor from concurrent.futures import Executor
@ -770,7 +783,7 @@ def reformat_many(
workers: Optional[int], workers: Optional[int],
) -> None: ) -> None:
"""Reformat multiple files using a ProcessPoolExecutor.""" """Reformat multiple files using a ProcessPoolExecutor."""
from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
executor: Executor executor: Executor
worker_count = workers if workers is not None else DEFAULT_WORKERS worker_count = workers if workers is not None else DEFAULT_WORKERS

View File

@ -1,7 +1,7 @@
"""Builds on top of nodes.py to track brackets.""" """Builds on top of nodes.py to track brackets."""
from dataclasses import dataclass, field
import sys import sys
from dataclasses import dataclass, field
from typing import Dict, Iterable, List, Optional, Tuple, Union from typing import Dict, Iterable, List, Optional, Tuple, Union
if sys.version_info < (3, 8): if sys.version_info < (3, 8):
@ -9,12 +9,20 @@
else: else:
from typing import Final 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 blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node
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
# types # types
LN = Union[Leaf, Node] LN = Union[Leaf, Node]

View File

@ -2,16 +2,14 @@
import os import os
import pickle import pickle
from pathlib import Path
import tempfile import tempfile
from pathlib import Path
from typing import Dict, Iterable, Set, Tuple from typing import Dict, Iterable, Set, Tuple
from platformdirs import user_cache_dir from platformdirs import user_cache_dir
from black.mode import Mode
from _black_version import version as __version__ from _black_version import version as __version__
from black.mode import Mode
# types # types
Timestamp = float Timestamp = float

View File

@ -1,7 +1,7 @@
import re
import sys import sys
from dataclasses import dataclass from dataclasses import dataclass
from functools import lru_cache from functools import lru_cache
import re
from typing import Iterator, List, Optional, Union from typing import Iterator, List, Optional, Union
if sys.version_info >= (3, 8): if sys.version_info >= (3, 8):
@ -9,11 +9,16 @@
else: else:
from typing_extensions import Final 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 blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node, type_repr
from black.nodes import first_leaf_column, preceding_leaf, container_of
from black.nodes import CLOSING_BRACKETS, STANDALONE_COMMENT, WHITESPACE
# types # types
LN = Union[Leaf, Node] LN = Union[Leaf, Node]

View File

@ -1,12 +1,11 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Iterator, TypeVar, Union 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.nodes import Visitor
from black.output import out from black.output import out
from black.parsing import lib2to3_parse from black.parsing import lib2to3_parse
from blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node, type_repr
LN = Union[Leaf, Node] LN = Union[Leaf, Node]
T = TypeVar("T") T = TypeVar("T")

View File

@ -1,9 +1,10 @@
from functools import lru_cache
import io import io
import os import os
from pathlib import Path
import sys import sys
from functools import lru_cache
from pathlib import Path
from typing import ( from typing import (
TYPE_CHECKING,
Any, Any,
Dict, Dict,
Iterable, Iterable,
@ -14,7 +15,6 @@
Sequence, Sequence,
Tuple, Tuple,
Union, Union,
TYPE_CHECKING,
) )
from mypy_extensions import mypyc_attr from mypy_extensions import mypyc_attr
@ -30,9 +30,9 @@
else: else:
import tomli as tomllib import tomli as tomllib
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
from black.output import err from black.output import err
from black.report import Report from black.report import Report
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
if TYPE_CHECKING: if TYPE_CHECKING:
import colorama # noqa: F401 import colorama # noqa: F401

View File

@ -1,22 +1,20 @@
"""Functions to process IPython magics with.""" """Functions to process IPython magics with."""
from functools import lru_cache
import dataclasses
import ast import ast
from typing import Dict, List, Tuple, Optional import collections
import dataclasses
import secrets import secrets
import sys import sys
import collections from functools import lru_cache
from typing import Dict, List, Optional, Tuple
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
from typing import TypeGuard from typing import TypeGuard
else: else:
from typing_extensions import TypeGuard from typing_extensions import TypeGuard
from black.report import NothingChanged
from black.output import out from black.output import out
from black.report import NothingChanged
TRANSFORMED_MAGICS = frozenset( 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 Mirrors the logic in `quiet` from `IPython.core.displayhook`, but uses
``tokenize_rt`` so that round-tripping works fine. ``tokenize_rt`` so that round-tripping works fine.
""" """
from tokenize_rt import ( from tokenize_rt import reversed_enumerate, src_to_tokens, tokens_to_src
src_to_tokens,
tokens_to_src,
reversed_enumerate,
)
tokens = src_to_tokens(src) tokens = src_to_tokens(src)
trailing_semicolon = False trailing_semicolon = False
@ -118,7 +112,7 @@ def put_trailing_semicolon_back(src: str, has_trailing_semicolon: bool) -> str:
""" """
if not has_trailing_semicolon: if not has_trailing_semicolon:
return src 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) tokens = src_to_tokens(src)
for idx, token in reversed_enumerate(tokens): for idx, token in reversed_enumerate(tokens):

View File

@ -1,38 +1,67 @@
""" """
Generating lines of code. Generating lines of code.
""" """
from functools import partial, wraps
import sys import sys
from functools import partial, wraps
from typing import Collection, Iterator, List, Optional, Set, Union, cast from typing import Collection, Iterator, List, Optional, Set, Union, cast
from black.nodes import WHITESPACE, RARROW, STATEMENT, STANDALONE_COMMENT from black.brackets import COMMA_PRIORITY, DOT_PRIORITY, max_delimiter_priority_in_atom
from black.nodes import ASSIGNMENTS, OPENING_BRACKETS, CLOSING_BRACKETS from black.comments import FMT_OFF, generate_comments, list_comments
from black.nodes import Visitor, syms, is_arith_like, ensure_visible 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 ( 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_docstring,
is_empty_tuple, is_empty_tuple,
is_one_tuple, is_lpar_token,
is_multiline_string,
is_name_token,
is_one_sequence_between, 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.numerics import normalize_numeric_literal
from black.strings import get_string_prefix, fix_docstring from black.strings import (
from black.strings import normalize_string_prefix, normalize_string_quotes fix_docstring,
from black.trans import Transformer, CannotTransform, StringMerger, StringSplitter get_string_prefix,
from black.trans import StringParenWrapper, StringParenStripper, hug_power_op normalize_string_prefix,
from black.mode import Mode, Feature, Preview normalize_string_quotes,
)
from blib2to3.pytree import Node, Leaf from black.trans import (
CannotTransform,
StringMerger,
StringParenStripper,
StringParenWrapper,
StringSplitter,
Transformer,
hug_power_op,
)
from blib2to3.pgen2 import token from blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node
# types # types
LeafID = int LeafID = int

View File

@ -1,6 +1,6 @@
from dataclasses import dataclass, field
import itertools import itertools
import sys import sys
from dataclasses import dataclass, field
from typing import ( from typing import (
Callable, Callable,
Dict, Dict,
@ -13,16 +13,25 @@
cast, cast,
) )
from blib2to3.pytree import Node, Leaf from black.brackets import DOT_PRIORITY, BracketTracker
from blib2to3.pgen2 import token
from black.brackets import BracketTracker, DOT_PRIORITY
from black.mode import Mode, Preview from black.mode import Mode, Preview
from black.nodes import STANDALONE_COMMENT, TEST_DESCENDANTS from black.nodes import (
from black.nodes import BRACKETS, OPENING_BRACKETS, CLOSING_BRACKETS BRACKETS,
from black.nodes import syms, whitespace, replace_child, child_towards CLOSING_BRACKETS,
from black.nodes import is_multiline_string, is_import, is_type_comment OPENING_BRACKETS,
from black.nodes import is_one_sequence_between 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 # types
T = TypeVar("T") T = TypeVar("T")

View File

@ -4,11 +4,10 @@
chosen by the user. chosen by the user.
""" """
from hashlib import sha256
import sys import sys
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum, auto from enum import Enum, auto
from hashlib import sha256
from operator import attrgetter from operator import attrgetter
from typing import Dict, Set from typing import Dict, Set
from warnings import warn from warnings import warn

View File

@ -3,16 +3,7 @@
""" """
import sys import sys
from typing import ( from typing import Generic, Iterator, List, Optional, Set, Tuple, TypeVar, Union
Generic,
Iterator,
List,
Optional,
Set,
Tuple,
TypeVar,
Union,
)
if sys.version_info >= (3, 8): if sys.version_info >= (3, 8):
from typing import Final from typing import Final
@ -25,14 +16,11 @@
from mypy_extensions import mypyc_attr 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.cache import CACHE_DIR
from black.strings import has_triple_quotes 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) pygram.initialize(CACHE_DIR)
syms: Final = pygram.python_symbols syms: Final = pygram.python_symbols

View File

@ -4,11 +4,11 @@
""" """
import json import json
from typing import Any, Optional
from mypy_extensions import mypyc_attr
import tempfile import tempfile
from typing import Any, Optional
from click import echo, style from click import echo, style
from mypy_extensions import mypyc_attr
@mypyc_attr(patchable=True) @mypyc_attr(patchable=True)

View File

@ -11,16 +11,14 @@
else: else:
from typing import Final from typing import Final
# lib2to3 fork from black.mode import Feature, TargetVersion, supports_feature
from blib2to3.pytree import Node, Leaf from black.nodes import syms
from blib2to3 import pygram from blib2to3 import pygram
from blib2to3.pgen2 import driver from blib2to3.pgen2 import driver
from blib2to3.pgen2.grammar import Grammar from blib2to3.pgen2.grammar import Grammar
from blib2to3.pgen2.parse import ParseError from blib2to3.pgen2.parse import ParseError
from blib2to3.pgen2.tokenize import TokenError from blib2to3.pgen2.tokenize import TokenError
from blib2to3.pytree import Leaf, Node
from black.mode import TargetVersion, Feature, supports_feature
from black.nodes import syms
ast3: Any ast3: Any

View File

@ -7,7 +7,7 @@
from click import style from click import style
from black.output import out, err from black.output import err, out
class Changed(Enum): class Changed(Enum):

View File

@ -4,7 +4,6 @@
""" """
from typing import Generic, TypeVar, Union from typing import Generic, TypeVar, Union
T = TypeVar("T") T = TypeVar("T")
E = TypeVar("E", bound=Exception) E = TypeVar("E", bound=Exception)

View File

@ -1,10 +1,11 @@
""" """
String transformers that can split and merge strings. String transformers that can split and merge strings.
""" """
import re
import sys
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass from dataclasses import dataclass
import re
from typing import ( from typing import (
Any, Any,
Callable, Callable,
@ -21,29 +22,38 @@
TypeVar, TypeVar,
Union, Union,
) )
import sys
if sys.version_info < (3, 8): if sys.version_info < (3, 8):
from typing_extensions import Literal, Final from typing_extensions import Final, Literal
else: else:
from typing import Literal, Final from typing import Literal, Final
from mypy_extensions import trait 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.brackets import BracketMatchError
from black.comments import contains_pragma_comment from black.comments import contains_pragma_comment
from black.strings import has_triple_quotes, get_string_prefix, assert_is_leaf_string from black.lines import Line, append_leaves
from black.strings import normalize_string_quotes from black.mode import Feature
from black.nodes import (
from blib2to3.pytree import Leaf, Node 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.pgen2 import token
from blib2to3.pytree import Leaf, Node
class CannotTransform(Exception): class CannotTransform(Exception):

View File

@ -8,6 +8,7 @@
try: try:
from aiohttp import web from aiohttp import web
from .middlewares import cors from .middlewares import cors
except ImportError as ie: except ImportError as ie:
raise ImportError( raise ImportError(
@ -16,11 +17,11 @@
+ "to obtain aiohttp_cors: `pip install black[d]`" + "to obtain aiohttp_cors: `pip install black[d]`"
) from None ) from None
import black
from black.concurrency import maybe_install_uvloop
import click import click
import black
from _black_version import version as __version__ 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 # This is used internally by tests to shut down the server prematurely
_stop_signal = asyncio.Event() _stop_signal = asyncio.Event()

View File

@ -1,7 +1,8 @@
from typing import Iterable, Awaitable, Callable from typing import Awaitable, Callable, Iterable
from aiohttp.web_response import StreamResponse
from aiohttp.web_request import Request
from aiohttp.web_middlewares import middleware from aiohttp.web_middlewares import middleware
from aiohttp.web_request import Request
from aiohttp.web_response import StreamResponse
Handler = Callable[[Request], Awaitable[StreamResponse]] Handler = Callable[[Request], Awaitable[StreamResponse]]
Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]] Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]

View File

@ -14,11 +14,11 @@
Adapted from https://pypi.org/project/pytest-optional-tests/, (c) 2019 Reece Hart Adapted from https://pypi.org/project/pytest-optional-tests/, (c) 2019 Reece Hart
""" """
from functools import lru_cache
import itertools import itertools
import logging import logging
import re 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 import pytest
@ -32,8 +32,8 @@
if TYPE_CHECKING: if TYPE_CHECKING:
from _pytest.config.argparsing import Parser
from _pytest.config import Config from _pytest.config import Config
from _pytest.config.argparsing import Parser
from _pytest.mark.structures import MarkDecorator from _pytest.mark.structures import MarkDecorator
from _pytest.nodes import Node from _pytest.nodes import Node

View File

@ -6,6 +6,7 @@
import logging import logging
import multiprocessing import multiprocessing
import os import os
import re
import sys import sys
import types import types
import unittest import unittest
@ -31,7 +32,6 @@
import click import click
import pytest import pytest
import re
from click import unstyle from click import unstyle
from click.testing import CliRunner from click.testing import CliRunner
from pathspec import PathSpec from pathspec import PathSpec
@ -59,8 +59,8 @@
dump_to_stderr, dump_to_stderr,
ff, ff,
fs, fs,
read_data,
get_case_path, get_case_path,
read_data,
read_data_from_file, read_data_from_file,
) )

View File

@ -2,15 +2,16 @@
from typing import Any from typing import Any
from unittest.mock import patch from unittest.mock import patch
from click.testing import CliRunner
import pytest import pytest
from click.testing import CliRunner
from tests.util import read_data, DETERMINISTIC_HEADER from tests.util import DETERMINISTIC_HEADER, read_data
try: try:
import blackd
from aiohttp.test_utils import AioHTTPTestCase
from aiohttp import web from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase
import blackd
except ImportError as e: except ImportError as e:
raise RuntimeError("Please install Black with the 'd' extra") from e raise RuntimeError("Please install Black with the 'd' extra") from e

View File

@ -8,10 +8,10 @@
from tests.util import ( from tests.util import (
DEFAULT_MODE, DEFAULT_MODE,
PY36_VERSIONS, PY36_VERSIONS,
all_data_cases,
assert_format, assert_format,
dump_to_stderr, dump_to_stderr,
read_data, read_data,
all_data_cases,
) )

View File

@ -1,23 +1,24 @@
import contextlib import contextlib
from dataclasses import replace
import pathlib import pathlib
import re import re
from contextlib import ExitStack as does_not_raise from contextlib import ExitStack as does_not_raise
from dataclasses import replace
from typing import ContextManager from typing import ContextManager
import pytest
from _pytest.monkeypatch import MonkeyPatch
from click.testing import CliRunner from click.testing import CliRunner
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
from black import ( from black import (
main, Mode,
NothingChanged, NothingChanged,
format_cell, format_cell,
format_file_contents, format_file_contents,
format_file_in_place, format_file_in_place,
main,
) )
import pytest from black.handle_ipynb_magics import jupyter_dependencies_are_installed
from black import Mode from tests.util import DATA_DIR, get_case_path, read_jupyter_notebook
from _pytest.monkeypatch import MonkeyPatch
from tests.util import DATA_DIR, read_jupyter_notebook, get_case_path
with contextlib.suppress(ModuleNotFoundError): with contextlib.suppress(ModuleNotFoundError):
import IPython import IPython

View File

@ -1,10 +1,11 @@
import pytest
import pathlib import pathlib
from tests.util import get_case_path import pytest
from black import main, jupyter_dependencies_are_installed
from click.testing import CliRunner 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 pytestmark = pytest.mark.no_jupyter
runner = CliRunner() runner = CliRunner()

View File

@ -1,4 +1,5 @@
from typing import List, Tuple from typing import List, Tuple
from black.trans import iter_fexpr_spans from black.trans import iter_fexpr_spans