Skip to content

Commit de161f8

Browse files
authored
Merge pull request #11896 from nicoddemus/isort
Replace reorder-python-imports by isort due to black incompatibility
2 parents e885013 + 3be2a9d commit de161f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+142
-147
lines changed

.gitblameignore renamed to .git-blame-ignore-revs

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ afc607cfd81458d4e4f3b1f3cf8cc931b933907e
2626

2727
# move argument parser to own file
2828
c9df77cbd6a365dcb73c39618e4842711817e871
29+
30+
# Replace reorder-python-imports by isort due to black incompatibility (#11896)
31+
8b54596639f41dfac070030ef20394b9001fe63c

.pre-commit-config.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 23.12.1
3+
rev: 24.1.1
44
hooks:
55
- id: black
66
args: [--safe, --quiet]
@@ -36,11 +36,12 @@ repos:
3636
additional_dependencies:
3737
- flake8-typing-imports==1.12.0
3838
- flake8-docstrings==1.5.0
39-
- repo: https://github.com/asottile/reorder-python-imports
40-
rev: v3.12.0
39+
- repo: https://github.com/pycqa/isort
40+
rev: 5.13.2
4141
hooks:
42-
- id: reorder-python-imports
43-
args: ['--application-directories=.:src', --py38-plus]
42+
- id: isort
43+
name: isort
44+
args: [--force-single-line, --profile=black]
4445
- repo: https://github.com/asottile/pyupgrade
4546
rev: v3.15.0
4647
hooks:

bench/bench.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
if __name__ == "__main__":
44
import cProfile
5-
import pytest # NOQA
65
import pstats
76

7+
import pytest # NOQA
8+
89
script = sys.argv[1:] if len(sys.argv) > 1 else ["empty.py"]
910
cProfile.run("pytest.cmdline.main(%r)" % script, "prof")
1011
p = pstats.Stats("prof")

doc/en/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,10 @@
440440

441441
def configure_logging(app: "sphinx.application.Sphinx") -> None:
442442
"""Configure Sphinx's WarningHandler to handle (expected) missing include."""
443-
import sphinx.util.logging
444443
import logging
445444

445+
import sphinx.util.logging
446+
446447
class WarnLogFilter(logging.Filter):
447448
def filter(self, record: logging.LogRecord) -> bool:
448449
"""Ignore warnings about missing include with "only" directive.

doc/en/example/multipython.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Module containing a parametrized tests testing cross-python serialization
22
via the pickle module."""
3+
34
import shutil
45
import subprocess
56
import textwrap
67

78
import pytest
89

9-
1010
pythonlist = ["python3.9", "python3.10", "python3.11"]
1111

1212

scripts/update-plugin-list.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from requests_cache import SQLiteCache
2020
from tqdm import tqdm
2121

22-
2322
FILE_HEAD = r"""
2423
.. Note this file is autogenerated by scripts/update-plugin-list.py - usually weekly via github action
2524

src/_pytest/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__all__ = ["__version__", "version_tuple"]
22

33
try:
4-
from ._version import version as __version__, version_tuple
4+
from ._version import version as __version__
5+
from ._version import version_tuple
56
except ImportError: # pragma: no cover
67
# broken installation, we don't even try
78
# unknown only works because we do poor mans version compare

src/_pytest/_argcomplete.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
which should throw a KeyError: 'COMPLINE' (which is properly set by the
6262
global argcomplete script).
6363
"""
64+
6465
import argparse
6566
import os
6667
import sys

src/_pytest/_code/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Python inspection/code generation API."""
2+
23
from .code import Code
34
from .code import ExceptionInfo
45
from .code import filter_traceback

src/_pytest/_code/code.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ def ishidden(self, excinfo: Optional["ExceptionInfo[BaseException]"]) -> bool:
278278
279279
Mostly for internal use.
280280
"""
281-
tbh: Union[
282-
bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]
283-
] = False
281+
tbh: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]] = (
282+
False
283+
)
284284
for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals):
285285
# in normal cases, f_locals and f_globals are dictionaries
286286
# however via `exec(...)` / `eval(...)` they can be other types
@@ -377,12 +377,10 @@ def cut(
377377
return self
378378

379379
@overload
380-
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry:
381-
...
380+
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: ...
382381

383382
@overload
384-
def __getitem__(self, key: slice) -> "Traceback":
385-
...
383+
def __getitem__(self, key: slice) -> "Traceback": ...
386384

387385
def __getitem__(
388386
self, key: Union["SupportsIndex", slice]
@@ -1056,13 +1054,13 @@ def repr_excinfo(
10561054
# full support for exception groups added to ExceptionInfo.
10571055
# See https://github.com/pytest-dev/pytest/issues/9159
10581056
if isinstance(e, BaseExceptionGroup):
1059-
reprtraceback: Union[
1060-
ReprTracebackNative, ReprTraceback
1061-
] = ReprTracebackNative(
1062-
traceback.format_exception(
1063-
type(excinfo_.value),
1064-
excinfo_.value,
1065-
excinfo_.traceback[0]._rawentry,
1057+
reprtraceback: Union[ReprTracebackNative, ReprTraceback] = (
1058+
ReprTracebackNative(
1059+
traceback.format_exception(
1060+
type(excinfo_.value),
1061+
excinfo_.value,
1062+
excinfo_.traceback[0]._rawentry,
1063+
)
10661064
)
10671065
)
10681066
else:

src/_pytest/_code/source.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ def __eq__(self, other: object) -> bool:
4747
__hash__ = None # type: ignore
4848

4949
@overload
50-
def __getitem__(self, key: int) -> str:
51-
...
50+
def __getitem__(self, key: int) -> str: ...
5251

5352
@overload
54-
def __getitem__(self, key: slice) -> "Source":
55-
...
53+
def __getitem__(self, key: slice) -> "Source": ...
5654

5755
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]:
5856
if isinstance(key, int):

src/_pytest/_io/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from .terminalwriter import get_terminal_width
22
from .terminalwriter import TerminalWriter
33

4-
54
__all__ = [
65
"TerminalWriter",
76
"get_terminal_width",

src/_pytest/_io/terminalwriter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Helper functions for writing to terminals and files."""
2+
23
import os
34
import shutil
45
import sys
@@ -10,7 +11,6 @@
1011

1112
from .wcwidth import wcswidth
1213

13-
1414
# This code was initially copied from py 1.8.1, file _io/terminalwriter.py.
1515

1616

@@ -210,8 +210,8 @@ def _highlight(
210210
from pygments.lexers.python import PythonLexer as Lexer
211211
elif lexer == "diff":
212212
from pygments.lexers.diff import DiffLexer as Lexer
213-
from pygments import highlight
214213
import pygments.util
214+
from pygments import highlight
215215
except ImportError:
216216
return source
217217
else:

src/_pytest/_py/error.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""create errno-specific classes for IO or os calls."""
2+
23
from __future__ import annotations
34

45
import errno

src/_pytest/_py/path.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,10 @@ class Stat:
204204
if TYPE_CHECKING:
205205

206206
@property
207-
def size(self) -> int:
208-
...
207+
def size(self) -> int: ...
209208

210209
@property
211-
def mtime(self) -> float:
212-
...
210+
def mtime(self) -> float: ...
213211

214212
def __getattr__(self, name: str) -> Any:
215213
return getattr(self._osstatresult, "st_" + name)
@@ -962,12 +960,10 @@ def ensure(self, *args, **kwargs):
962960
return p
963961

964962
@overload
965-
def stat(self, raising: Literal[True] = ...) -> Stat:
966-
...
963+
def stat(self, raising: Literal[True] = ...) -> Stat: ...
967964

968965
@overload
969-
def stat(self, raising: Literal[False]) -> Stat | None:
970-
...
966+
def stat(self, raising: Literal[False]) -> Stat | None: ...
971967

972968
def stat(self, raising: bool = True) -> Stat | None:
973969
"""Return an os.stat() tuple."""
@@ -1168,7 +1164,8 @@ def sysexec(self, *argv: os.PathLike[str], **popen_opts: Any) -> str:
11681164
where the 'self' path points to executable.
11691165
The process is directly invoked and not through a system shell.
11701166
"""
1171-
from subprocess import Popen, PIPE
1167+
from subprocess import PIPE
1168+
from subprocess import Popen
11721169

11731170
popen_opts.pop("stdout", None)
11741171
popen_opts.pop("stderr", None)

src/_pytest/assertion/rewrite.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Rewrite assertion AST to produce nice error messages."""
2+
23
import ast
34
import errno
45
import functools
@@ -33,15 +34,16 @@
3334
from _pytest._io.saferepr import saferepr
3435
from _pytest._version import version
3536
from _pytest.assertion import util
36-
from _pytest.assertion.util import ( # noqa: F401
37-
format_explanation as _format_explanation,
38-
)
3937
from _pytest.config import Config
4038
from _pytest.main import Session
4139
from _pytest.pathlib import absolutepath
4240
from _pytest.pathlib import fnmatch_ex
4341
from _pytest.stash import StashKey
4442

43+
# fmt: off
44+
from _pytest.assertion.util import format_explanation as _format_explanation # noqa:F401, isort:skip
45+
# fmt:on
46+
4547
if TYPE_CHECKING:
4648
from _pytest.assertion import AssertionState
4749

@@ -669,9 +671,9 @@ def __init__(
669671
self.enable_assertion_pass_hook = False
670672
self.source = source
671673
self.scope: tuple[ast.AST, ...] = ()
672-
self.variables_overwrite: defaultdict[
673-
tuple[ast.AST, ...], Dict[str, str]
674-
] = defaultdict(dict)
674+
self.variables_overwrite: defaultdict[tuple[ast.AST, ...], Dict[str, str]] = (
675+
defaultdict(dict)
676+
)
675677

676678
def run(self, mod: ast.Module) -> None:
677679
"""Find all assert statements in *mod* and rewrite them."""
@@ -858,9 +860,10 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]:
858860
the expression is false.
859861
"""
860862
if isinstance(assert_.test, ast.Tuple) and len(assert_.test.elts) >= 1:
861-
from _pytest.warning_types import PytestAssertRewriteWarning
862863
import warnings
863864

865+
from _pytest.warning_types import PytestAssertRewriteWarning
866+
864867
# TODO: This assert should not be needed.
865868
assert self.module_path is not None
866869
warnings.warn_explicit(

src/_pytest/assertion/truncate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Current default behaviour is to truncate assertion explanations at
44
terminal lines, unless running with an assertions verbosity level of at least 2 or running on CI.
55
"""
6+
67
from typing import List
78
from typing import Optional
89

910
from _pytest.assertion import util
1011
from _pytest.config import Config
1112
from _pytest.nodes import Item
1213

13-
1414
DEFAULT_MAX_LINES = 8
1515
DEFAULT_MAX_CHARS = 8 * 80
1616
USAGE_MSG = "use '-vv' to show"

src/_pytest/cacheprovider.py

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def warn(self, fmt: str, *, _ispytest: bool = False, **args: object) -> None:
112112
"""
113113
check_ispytest(_ispytest)
114114
import warnings
115+
115116
from _pytest.warning_types import PytestCacheWarning
116117

117118
warnings.warn(

src/_pytest/compat.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import NoReturn
1818
from typing import TypeVar
1919

20-
2120
_T = TypeVar("_T")
2221
_S = TypeVar("_S")
2322

src/_pytest/config/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
from _pytest.warning_types import warn_explicit_for
6767

6868
if TYPE_CHECKING:
69+
from .argparsing import Argument
70+
from .argparsing import Parser
6971
from _pytest._code.code import _TracebackStyle
7072
from _pytest.terminal import TerminalReporter
71-
from .argparsing import Argument, Parser
7273

7374

7475
_PluggyPlugin = object
@@ -973,7 +974,8 @@ def __init__(
973974
*,
974975
invocation_params: Optional[InvocationParams] = None,
975976
) -> None:
976-
from .argparsing import Parser, FILE_OR_DIR
977+
from .argparsing import FILE_OR_DIR
978+
from .argparsing import Parser
977979

978980
if invocation_params is None:
979981
invocation_params = self.InvocationParams(
@@ -1390,8 +1392,9 @@ def _validate_plugins(self) -> None:
13901392
return
13911393

13921394
# Imported lazily to improve start-up time.
1395+
from packaging.requirements import InvalidRequirement
1396+
from packaging.requirements import Requirement
13931397
from packaging.version import Version
1394-
from packaging.requirements import InvalidRequirement, Requirement
13951398

13961399
plugin_info = self.pluginmanager.list_plugin_distinfo()
13971400
plugin_dist_info = {dist.project_name: dist.version for _, dist in plugin_info}

src/_pytest/deprecated.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:class:`PytestWarning`, or :class:`UnformattedWarning`
99
in case of warnings which need to format their messages.
1010
"""
11+
1112
from warnings import warn
1213

1314
from _pytest.warning_types import PytestDeprecationWarning

src/_pytest/faulthandler.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from _pytest.nodes import Item
99
from _pytest.stash import StashKey
1010

11-
1211
fault_handler_original_stderr_fd_key = StashKey[int]()
1312
fault_handler_stderr_fd_key = StashKey[int]()
1413

0 commit comments

Comments
 (0)