Skip to content

Commit 06e5923

Browse files
authored
[8.0.x] Replace reorder-python-imports by isort due to black incompatibility (#11898)
Backport of #11896
1 parent a76aa6f commit 06e5923

Some content is hidden

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

84 files changed

+175
-149
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
@@ -441,9 +441,10 @@
441441

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

446+
import sphinx.util.logging
447+
447448
class WarnLogFilter(logging.Filter):
448449
def filter(self, record: logging.LogRecord) -> bool:
449450
"""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
@@ -277,9 +277,9 @@ def ishidden(self, excinfo: Optional["ExceptionInfo[BaseException]"]) -> bool:
277277
278278
Mostly for internal use.
279279
"""
280-
tbh: Union[
281-
bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]
282-
] = False
280+
tbh: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]] = (
281+
False
282+
)
283283
for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals):
284284
# in normal cases, f_locals and f_globals are dictionaries
285285
# however via `exec(...)` / `eval(...)` they can be other types
@@ -376,12 +376,10 @@ def cut(
376376
return self
377377

378378
@overload
379-
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry:
380-
...
379+
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: ...
381380

382381
@overload
383-
def __getitem__(self, key: slice) -> "Traceback":
384-
...
382+
def __getitem__(self, key: slice) -> "Traceback": ...
385383

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

src/_pytest/_code/source.py

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

4848
@overload
49-
def __getitem__(self, key: int) -> str:
50-
...
49+
def __getitem__(self, key: int) -> str: ...
5150

5251
@overload
53-
def __getitem__(self, key: slice) -> "Source":
54-
...
52+
def __getitem__(self, key: slice) -> "Source": ...
5553

5654
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]:
5755
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

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""local path implementation."""
2+
23
from __future__ import annotations
34

45
import atexit
@@ -203,12 +204,10 @@ class Stat:
203204
if TYPE_CHECKING:
204205

205206
@property
206-
def size(self) -> int:
207-
...
207+
def size(self) -> int: ...
208208

209209
@property
210-
def mtime(self) -> float:
211-
...
210+
def mtime(self) -> float: ...
212211

213212
def __getattr__(self, name: str) -> Any:
214213
return getattr(self._osstatresult, "st_" + name)
@@ -961,12 +960,10 @@ def ensure(self, *args, **kwargs):
961960
return p
962961

963962
@overload
964-
def stat(self, raising: Literal[True] = ...) -> Stat:
965-
...
963+
def stat(self, raising: Literal[True] = ...) -> Stat: ...
966964

967965
@overload
968-
def stat(self, raising: Literal[False]) -> Stat | None:
969-
...
966+
def stat(self, raising: Literal[False]) -> Stat | None: ...
970967

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

11721170
popen_opts.pop("stdout", None)
11731171
popen_opts.pop("stderr", None)

src/_pytest/assertion/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Support for presenting detailed information in failing assertions."""
2+
23
import sys
34
from typing import Any
45
from typing import Generator

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/assertion/util.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for assertion debugging."""
2+
23
import collections.abc
34
import os
45
import pprint

src/_pytest/cacheprovider.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Implementation of the cache provider."""
2+
23
# This plugin was not named "cache" to avoid conflicts with the external
34
# pytest-cache version.
45
import dataclasses
@@ -111,6 +112,7 @@ def warn(self, fmt: str, *, _ispytest: bool = False, **args: object) -> None:
111112
"""
112113
check_ispytest(_ispytest)
113114
import warnings
115+
114116
from _pytest.warning_types import PytestCacheWarning
115117

116118
warnings.warn(

src/_pytest/capture.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Per-test stdout/stderr capturing mechanism."""
2+
23
import abc
34
import collections
45
import contextlib

src/_pytest/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Python version compatibility code."""
2+
23
from __future__ import annotations
34

45
import dataclasses
@@ -18,7 +19,6 @@
1819

1920
import py
2021

21-
2222
_T = TypeVar("_T")
2323
_S = TypeVar("_S")
2424

0 commit comments

Comments
 (0)