Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions isort/_vendored/tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
{
"\\b": "\u0008", # backspace
"\\t": "\u0009", # tab
"\\n": "\u000A", # linefeed
"\\f": "\u000C", # form feed
"\\r": "\u000D", # carriage return
"\\n": "\u000a", # linefeed
"\\f": "\u000c", # form feed
"\\r": "\u000d", # carriage return
'\\"': "\u0022", # quote
"\\\\": "\u005C", # backslash
"\\\\": "\u005c", # backslash
}
)

Expand Down
2 changes: 1 addition & 1 deletion isort/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def imports(

from_import = parts[0].split(" ")
import_string = (" cimport " if cimports else " import ").join(
[from_import[0] + " " + "".join(from_import[1:])] + parts[1:]
[from_import[0] + " " + "".join(from_import[1:]), *parts[1:]]
)

just_imports = [
Expand Down
2 changes: 1 addition & 1 deletion isort/literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def register_type(
"""Registers a new literal sort type."""

def wrap(
function: Callable[[Any, ISortPrettyPrinter], str]
function: Callable[[Any, ISortPrettyPrinter], str],
) -> Callable[[Any, ISortPrettyPrinter], str]:
type_mapping[name] = (kind, function)
return function
Expand Down
2 changes: 1 addition & 1 deletion isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
print(ASCII_ART)

if jobs:
import multiprocessing
import multiprocessing # noqa: PLC0415

executor = multiprocessing.Pool(jobs if jobs > 0 else multiprocessing.cpu_count())
attempt_iterator = executor.imap(
Expand Down
4 changes: 2 additions & 2 deletions isort/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
out_lines = []
original_line_count = len(in_lines)
if config.old_finders:
from .deprecated.finders import FindersManager
from .deprecated.finders import FindersManager # noqa: PLC0415

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

from_import = parts[0].split(" ")
import_string = (" cimport " if cimports else " import ").join(
[from_import[0] + " " + "".join(from_import[1:])] + parts[1:]
[from_import[0] + " " + "".join(from_import[1:]), *parts[1:]]
)

just_imports = [
Expand Down
4 changes: 2 additions & 2 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,9 @@ def entry_points(group: str) -> "EntryPoints":
TODO: The reason for lazy loading here are unknown.
"""
if sys.version_info < (3, 10): # pragma: no cover
from importlib_metadata import entry_points as ep
from importlib_metadata import entry_points as ep # noqa: PLC0415
else:
from importlib.metadata import entry_points as ep
from importlib.metadata import entry_points as ep # noqa: PLC0415

return ep(group=group)

Expand Down
35 changes: 17 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,41 +115,39 @@ build-backend = "hatchling.build"

[dependency-groups]
dev = [
"bandit>=1.7.7",
"black>=24.3.0",
"bandit>=1.8.6",
"black>=25.9.0",
"colorama>=0.4.6",
"coverage[toml]>=6.5.0",
"cruft>=2.12.0",
"coverage[toml]>=7.10.7",
"cruft>=2.16.0",
"example-isort-sorting-plugin>=0.1.0",
"example-shared-isort-profile>=0.1.0",
"flake8>=3.8.4",
"flake8-bugbear>=22.12.12",
"flake8>=7.3.0",
"flake8-bugbear>=24.12.12",
"flake8-pyproject>=1.2.3",
"hatch>=1.14.0",
"httpx>=0.13.3",
"hypothesis>=6.10.1",
"hypothesmith>=0.1.3",
"libcst>=0.3.18",
"mypy>=1.14.1",
"pep8-naming>=0.8.2",
"hypothesis>=6.140.3",
"hypothesmith>=0.3.3",
"libcst>=1.8.5",
"mypy>=1.18.2",
"pep8-naming>=0.15.1",
"pip>=21.1.1",
"pip_api>=0.0.12",
"pipreqs>=0.4.9",
"portray>=1.8.0",
"pre-commit>=2.13.0",
"pytest>=7.4.2",
"pytest-benchmark>=3.4.1",
"ruff>=0.9.6",
"pytest>=8.4.2",
"pytest-benchmark>=5.1.0",
"ruff>=0.13.3",
"setuptools>=75.8.0",
"stdlibs>=2024.10.21.16",
"toml>=0.10.2",
"tox>=4.24.1",
"tox-uv>=1.25.0",
"tox>=4.30.3",
"tox-uv>=1.28.0",
"types-colorama>=0.4.2",
"types-setuptools>=70.0.0.20240523",
"types-toml>=0.1.3",
"uv>=0.8.23",
"vulture>=1.0",
]

[tool.flake8]
Expand Down Expand Up @@ -205,6 +203,7 @@ lint.ignore = [
"B904",
"E501",
"PERF203",
"PT030", # Too much work to turn on for now
"RUF100",
]
lint.exclude = [ "isort/_vendored/*" ]
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_deprecated_finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import posixpath
from pathlib import Path
from typing import Optional
from unittest.mock import patch

from isort import sections, settings
Expand Down Expand Up @@ -30,7 +31,7 @@ def test_no_finders(self):

def test_find_broken_finder(self):
class ExceptionOnFind(finders.BaseFinder):
def find(*args, **kwargs):
def find(self, module_name: str) -> Optional[str]:
raise ValueError("test")

assert (
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_importable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Basic set of tests to ensure entire code base is importable"""

# ruff: noqa: PLC0415

import pytest


Expand Down
11 changes: 3 additions & 8 deletions tests/unit/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from isort.exceptions import ExistingSyntaxErrors, FileSkipped, MissingSection
from isort.settings import Config
from isort.utils import exists_case_sensitive
from isort.main import parse_args
from isort.main import main

from .utils import UnreadableStream, as_stream

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


def test_argument_parsing() -> None:
from isort.main import parse_args

args = parse_args(["--dt", "-t", "foo", "--skip=bar", "baz.py", "--os"])
assert args["order_by_type"] is False
assert args["force_to_top"] == ["foo"]
Expand All @@ -3778,8 +3778,6 @@ def test_argument_parsing() -> None:

@pytest.mark.parametrize("multiprocess", [False, True])
def test_command_line(tmpdir, capfd, multiprocess: bool) -> None:
from isort.main import main

tmpdir.join("file1.py").write("import re\nimport os\n\nimport contextlib\n\n\nimport isort")
tmpdir.join("file2.py").write(
"import collections\nimport time\n\nimport abc" "\n\n\nimport isort"
Expand Down Expand Up @@ -3808,7 +3806,6 @@ def test_command_line(tmpdir, capfd, multiprocess: bool) -> None:
def test_quiet(tmpdir, capfd, quiet: bool) -> None:
if sys.platform.startswith("win"):
return
from isort.main import main

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


def test_python_version() -> None:
from isort.main import parse_args

# test that the py_version can be added as flag
args = parse_args(["--py=27"])
assert args["py_version"] == "27"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_invalid_syntax():


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


Expand Down
23 changes: 13 additions & 10 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_sort_imports_error_handling(tmpdir, capsys):
):
main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore # noqa

out, error = capsys.readouterr()
_, error = capsys.readouterr()
assert "Unrecoverable exception thrown when parsing" in error


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

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

# This should raise an error if an invalid settings path is provided
with pytest.raises(InvalidSettingsPath):
main.main(
base_args[2:]
+ ["--show-config"]
+ ["--settings-path", "/random-root-folder-that-cant-exist-right?"]
[
*base_args[2:],
"--show-config",
"--settings-path",
"/random-root-folder-that-cant-exist-right?",
]
)

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

assert "No valid encodings." in error

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

main.main([str(tmp_file), str(normal_file), "--verbose"])
out, error = capsys.readouterr()
_, error = capsys.readouterr()


def test_stream_skip_file(tmpdir, capsys):
Expand All @@ -914,13 +917,13 @@ def test_stream_skip_file(tmpdir, capsys):
"""
stream_with_skip = as_stream(input_with_skip)
main.main(["-"], stdin=stream_with_skip)
out, error = capsys.readouterr()
out, _ = capsys.readouterr()
assert out == input_with_skip

input_without_skip = input_with_skip.replace("isort: skip_file", "generic comment")
stream_without_skip = as_stream(input_without_skip)
main.main(["-"], stdin=stream_without_skip)
out, error = capsys.readouterr()
out, _ = capsys.readouterr()
assert (
out
== """
Expand All @@ -933,7 +936,7 @@ def test_stream_skip_file(tmpdir, capsys):
atomic_input_without_skip = input_with_skip.replace("isort: skip_file", "generic comment")
stream_without_skip = as_stream(atomic_input_without_skip)
main.main(["-", "--atomic"], stdin=stream_without_skip)
out, error = capsys.readouterr()
out, _ = capsys.readouterr()
assert (
out
== """
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_invalid_settings_path(self):
Config(settings_path="this_couldnt_possibly_actually_exists/could_it")

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

def test_invalid_profile(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_setuptools_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from setuptools.dist import Distribution

from isort import setuptools_commands


def test_isort_command_smoke(src_dir):
"""A basic smoke test for the setuptools_commands command"""
from setuptools.dist import Distribution

command = setuptools_commands.ISortCommand(Distribution())
command.distribution.packages = ["isort"]
Expand Down
Loading