Skip to content

Commit 47cc9c6

Browse files
committed
Lint Python code with ruff
1 parent 6f29cb9 commit 47cc9c6

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

docs/contributing/2.-coding-standard.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ All code submitted to hug should run through the following tools:
5252
- Flake8
5353
- flake8-bugbear
5454
- Bandit
55+
- ruff
5556
- pep8-naming
5657
- vulture
5758
- safety

isort/settings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,11 @@ def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any
892892

893893
for key, value in settings.items():
894894
existing_value_type = _get_str_to_type_converter(key)
895-
if existing_value_type == tuple:
895+
if existing_value_type is tuple:
896896
settings[key] = tuple(_as_list(value))
897-
elif existing_value_type == frozenset:
897+
elif existing_value_type is frozenset:
898898
settings[key] = frozenset(_as_list(settings.get(key))) # type: ignore
899-
elif existing_value_type == bool:
899+
elif existing_value_type is bool:
900900
# Only some configuration formats support native boolean values.
901901
if not isinstance(value, bool):
902902
value = _as_bool(value)

pyproject.toml

+32
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ dev = [
133133
"pytest-benchmark>=3.4.1",
134134
"pytest-mock>=1.10",
135135
"requirementslib>=1.5",
136+
"ruff>=0.9.6",
136137
"safety>=2.2.0",
137138
"stdlibs>=2024.10.21.16",
138139
"toml>=0.10.2",
@@ -169,6 +170,37 @@ allow_untyped_defs = true
169170
allow_incomplete_defs = true
170171
allow_untyped_calls = true
171172

173+
[tool.ruff]
174+
line-length = 100
175+
lint.select = [
176+
"ASYNC",
177+
"B",
178+
"C4",
179+
"C90",
180+
"E",
181+
"F",
182+
"FLY",
183+
"PIE",
184+
"S",
185+
"W",
186+
]
187+
lint.ignore = [
188+
"B017",
189+
"B028",
190+
"B904",
191+
"E203",
192+
"E501",
193+
]
194+
lint.exclude = [ "_vendored" ]
195+
lint.mccabe.max-complexity = 91 # Default is 10
196+
197+
[tool.ruff.lint.per-file-ignores]
198+
"isort/hooks.py" = [ "S603" ]
199+
"isort/settings.py" = [ "S603", "S607" ]
200+
"tests/*" = [ "S" ]
201+
"tests/unit/example_crlf_file.py" = [ "F401" ]
202+
"tests/unit/test_wrap_modes.py" = [ "PIE804" ]
203+
172204
[tool.isort]
173205
profile = "hug"
174206
src_paths = ["isort", "tests"]

scripts/build_profile_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/env python
22
import os
3-
from typing import Any, Dict, Generator, Iterable, Type
3+
from typing import Any, Dict
44

55
from isort.profiles import profiles
66

scripts/lint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ uv run black --target-version py39 --check .
77
uv run isort --profile hug --check --diff isort/ tests/
88
uv run isort --profile hug --check --diff example_*/
99
uv run --with=Flake8-pyproject flake8 isort/ tests/
10+
uv run ruff check
1011
# 51457: https://github.com/tiangolo/typer/discussions/674
1112
# 72715: https://github.com/timothycrosley/portray/issues/95
1213
uv run safety check -i 72715 -i 51457 -i 59587

tests/unit/test_exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def setup_class(self):
8686

8787
def test_variables(self):
8888
assert self.instance.code == "x = ["
89-
assert self.instance.original_error == SyntaxError
89+
assert self.instance.original_error is SyntaxError
9090

9191

9292
class TestLiteralSortTypeMismatch(TestISortError):
@@ -96,8 +96,8 @@ def setup_class(self):
9696
)
9797

9898
def test_variables(self):
99-
assert self.instance.kind == tuple
100-
assert self.instance.expected_kind == list
99+
assert self.instance.kind is tuple
100+
assert self.instance.expected_kind is list
101101

102102

103103
class TestAssignmentsFormatMismatch(TestISortError):

uv.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)