Skip to content

Commit ac39eb1

Browse files
committed
Bump ruff to latest and fix code
1 parent fa3413f commit ac39eb1

File tree

12 files changed

+52
-50
lines changed

12 files changed

+52
-50
lines changed

isort/identify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def imports(
159159

160160
from_import = parts[0].split(" ")
161161
import_string = (" cimport " if cimports else " import ").join(
162-
[from_import[0] + " " + "".join(from_import[1:])] + parts[1:]
162+
[from_import[0] + " " + "".join(from_import[1:]), *parts[1:]]
163163
)
164164

165165
just_imports = [

isort/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
11931193
print(ASCII_ART)
11941194

11951195
if jobs:
1196-
import multiprocessing
1196+
import multiprocessing # noqa: PLC0415
11971197

11981198
executor = multiprocessing.Pool(jobs if jobs > 0 else multiprocessing.cpu_count())
11991199
attempt_iterator = executor.imap(

isort/parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
151151
out_lines = []
152152
original_line_count = len(in_lines)
153153
if config.old_finders:
154-
from .deprecated.finders import FindersManager
154+
from .deprecated.finders import FindersManager # noqa: PLC0415
155155

156156
finder = FindersManager(config=config).find
157157
else:
@@ -372,7 +372,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
372372

373373
from_import = parts[0].split(" ")
374374
import_string = (" cimport " if cimports else " import ").join(
375-
[from_import[0] + " " + "".join(from_import[1:])] + parts[1:]
375+
[from_import[0] + " " + "".join(from_import[1:]), *parts[1:]]
376376
)
377377

378378
just_imports = [

isort/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ def entry_points(group: str) -> "EntryPoints":
931931
TODO: The reason for lazy loading here are unknown.
932932
"""
933933
if sys.version_info < (3, 10): # pragma: no cover
934-
from importlib_metadata import entry_points as ep
934+
from importlib_metadata import entry_points as ep # noqa: PLC0415
935935
else:
936-
from importlib.metadata import entry_points as ep
936+
from importlib.metadata import entry_points as ep # noqa: PLC0415
937937

938938
return ep(group=group)
939939

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ dev = [
138138
"portray>=1.8.0",
139139
"pytest>=8.4.2",
140140
"pytest-benchmark>=5.1.0",
141-
"ruff>=0.9.6",
141+
"ruff>=0.13.3",
142142
"setuptools>=75.8.0",
143143
"stdlibs>=2024.10.21.16",
144144
"toml>=0.10.2",
@@ -203,6 +203,7 @@ lint.ignore = [
203203
"B904",
204204
"E501",
205205
"PERF203",
206+
"PT030", # Too much work to turn on for now
206207
"RUF100",
207208
]
208209
lint.exclude = [ "isort/_vendored/*" ]

tests/unit/test_importable.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Basic set of tests to ensure entire code base is importable"""
22

3+
# ruff: noqa: PLC0415
4+
35
import pytest
46

57

tests/unit/test_isort.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from isort.exceptions import ExistingSyntaxErrors, FileSkipped, MissingSection
2121
from isort.settings import Config
2222
from isort.utils import exists_case_sensitive
23+
from isort.main import parse_args
24+
from isort.main import main
2325

2426
from .utils import UnreadableStream, as_stream
2527

@@ -3762,12 +3764,10 @@ def test_monkey_patched_urllib() -> None:
37623764
with pytest.raises(ImportError):
37633765
# Previous versions of isort monkey patched urllib which caused unusual
37643766
# importing for other projects.
3765-
from urllib import quote # type: ignore # noqa: F401
3767+
from urllib import quote # type: ignore # noqa: F401, PLC0415
37663768

37673769

37683770
def test_argument_parsing() -> None:
3769-
from isort.main import parse_args
3770-
37713771
args = parse_args(["--dt", "-t", "foo", "--skip=bar", "baz.py", "--os"])
37723772
assert args["order_by_type"] is False
37733773
assert args["force_to_top"] == ["foo"]
@@ -3778,8 +3778,6 @@ def test_argument_parsing() -> None:
37783778

37793779
@pytest.mark.parametrize("multiprocess", [False, True])
37803780
def test_command_line(tmpdir, capfd, multiprocess: bool) -> None:
3781-
from isort.main import main
3782-
37833781
tmpdir.join("file1.py").write("import re\nimport os\n\nimport contextlib\n\n\nimport isort")
37843782
tmpdir.join("file2.py").write(
37853783
"import collections\nimport time\n\nimport abc" "\n\n\nimport isort"
@@ -3808,7 +3806,6 @@ def test_command_line(tmpdir, capfd, multiprocess: bool) -> None:
38083806
def test_quiet(tmpdir, capfd, quiet: bool) -> None:
38093807
if sys.platform.startswith("win"):
38103808
return
3811-
from isort.main import main
38123809

38133810
tmpdir.join("file1.py").write("import re\nimport os")
38143811
tmpdir.join("file2.py").write("")
@@ -4602,8 +4599,6 @@ def test_move_class_issue_751() -> None:
46024599

46034600

46044601
def test_python_version() -> None:
4605-
from isort.main import parse_args
4606-
46074602
# test that the py_version can be added as flag
46084603
args = parse_args(["--py=27"])
46094604
assert args["py_version"] == "27"

tests/unit/test_literal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_invalid_syntax():
1515

1616

1717
def test_invalid_sort_type():
18-
with pytest.raises(ValueError, match="Trying to sort using an undefined sort_type. Defined"):
18+
with pytest.raises(ValueError, match=r"Trying to sort using an undefined sort_type. Defined"):
1919
isort.literal.assignment("x = [1, 2, 3", "tuple-list-not-exist", "py")
2020

2121

tests/unit/test_main.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_sort_imports_error_handling(tmpdir, capsys):
6666
):
6767
main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore # noqa
6868

69-
out, error = capsys.readouterr()
69+
_, error = capsys.readouterr()
7070
assert "Unrecoverable exception thrown when parsing" in error
7171

7272

@@ -189,16 +189,19 @@ def test_main(capsys, tmpdir):
189189
assert returned_config["virtual_env"] == str(tmpdir)
190190

191191
# This should work even if settings path is not provided
192-
main.main(base_args[2:] + ["--show-config"])
192+
main.main([*base_args[2:], "--show-config"])
193193
out, error = capsys.readouterr()
194194
assert json.loads(out)["virtual_env"] == str(tmpdir)
195195

196196
# This should raise an error if an invalid settings path is provided
197197
with pytest.raises(InvalidSettingsPath):
198198
main.main(
199-
base_args[2:]
200-
+ ["--show-config"]
201-
+ ["--settings-path", "/random-root-folder-that-cant-exist-right?"]
199+
[
200+
*base_args[2:],
201+
"--show-config",
202+
"--settings-path",
203+
"/random-root-folder-that-cant-exist-right?",
204+
]
202205
)
203206

204207
# Should be able to set settings path to a file
@@ -894,7 +897,7 @@ def test_unsupported_encodings(tmpdir, capsys):
894897
# should throw an error if only unsupported encoding provided
895898
with pytest.raises(SystemExit):
896899
main.main([str(tmp_file)])
897-
out, error = capsys.readouterr()
900+
_, error = capsys.readouterr()
898901

899902
assert "No valid encodings." in error
900903

@@ -903,7 +906,7 @@ def test_unsupported_encodings(tmpdir, capsys):
903906
normal_file.write("import os\nimport sys")
904907

905908
main.main([str(tmp_file), str(normal_file), "--verbose"])
906-
out, error = capsys.readouterr()
909+
_, error = capsys.readouterr()
907910

908911

909912
def test_stream_skip_file(tmpdir, capsys):
@@ -914,13 +917,13 @@ def test_stream_skip_file(tmpdir, capsys):
914917
"""
915918
stream_with_skip = as_stream(input_with_skip)
916919
main.main(["-"], stdin=stream_with_skip)
917-
out, error = capsys.readouterr()
920+
out, _ = capsys.readouterr()
918921
assert out == input_with_skip
919922

920923
input_without_skip = input_with_skip.replace("isort: skip_file", "generic comment")
921924
stream_without_skip = as_stream(input_without_skip)
922925
main.main(["-"], stdin=stream_without_skip)
923-
out, error = capsys.readouterr()
926+
out, _ = capsys.readouterr()
924927
assert (
925928
out
926929
== """
@@ -933,7 +936,7 @@ def test_stream_skip_file(tmpdir, capsys):
933936
atomic_input_without_skip = input_with_skip.replace("isort: skip_file", "generic comment")
934937
stream_without_skip = as_stream(atomic_input_without_skip)
935938
main.main(["-", "--atomic"], stdin=stream_without_skip)
936-
out, error = capsys.readouterr()
939+
out, _ = capsys.readouterr()
937940
assert (
938941
out
939942
== """

tests/unit/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_invalid_settings_path(self):
3434
Config(settings_path="this_couldnt_possibly_actually_exists/could_it")
3535

3636
def test_invalid_pyversion(self):
37-
with pytest.raises(ValueError, match="The python version 10 is not supported."):
37+
with pytest.raises(ValueError, match=r"The python version 10 is not supported."):
3838
Config(py_version=10)
3939

4040
def test_invalid_profile(self):

0 commit comments

Comments
 (0)