Skip to content

Commit 514376f

Browse files
[ruff] Add ruff's check and autofix existing issues
1 parent bdfc5c8 commit 514376f

19 files changed

+39
-36
lines changed

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ select = [
133133
"F", # pyflakes
134134
"I", # isort
135135
"UP", # pyupgrade
136+
"RUF", # ruff
136137
"W", # pycodestyle
137138
]
138139
ignore = [
@@ -156,6 +157,12 @@ ignore = [
156157
"D402", # First line should not be the function's signature
157158
"D404", # First word of the docstring should not be "This"
158159
"D415", # First line should end with a period, question mark, or exclamation point
160+
# ruff ignore
161+
"RUF001", # String contains ambiguous character
162+
"RUF003", # Comment contains ambiguous character
163+
"RUF005", # Consider `(x, *y)` instead of concatenation
164+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
165+
"RUF015", # Prefer `next(iter(x))` over single element slice
159166
]
160167

161168
[tool.ruff.format]

src/_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def _truncate_recursive_traceback(
10181018
extraline: Optional[str] = (
10191019
"!!! Recursion error detected, but an error occurred locating the origin of recursion.\n"
10201020
" The following exception happened when comparing locals in the stack frame:\n"
1021-
f" {type(e).__name__}: {str(e)}\n"
1021+
f" {type(e).__name__}: {e!s}\n"
10221022
f" Displaying first and last {max_frames} stack frames out of {len(traceback)}."
10231023
)
10241024
# Type ignored because adding two instances of a List subtype

src/_pytest/_py/path.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,7 @@ def pyimport(self, modname=None, ensuresyspath=True):
11051105
modname = self.purebasename
11061106
spec = importlib.util.spec_from_file_location(modname, str(self))
11071107
if spec is None or spec.loader is None:
1108-
raise ImportError(
1109-
f"Can't find module {modname} at location {str(self)}"
1110-
)
1108+
raise ImportError(f"Can't find module {modname} at location {self!s}")
11111109
mod = importlib.util.module_from_spec(spec)
11121110
spec.loader.exec_module(mod)
11131111
return mod

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions
2828
class NotSetType(enum.Enum):
2929
token = 0
30-
NOTSET: Final = NotSetType.token # noqa: E305
30+
NOTSET: Final = NotSetType.token
3131
# fmt: on
3232

3333

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def _importconftest(
671671
if dirpath in path.parents or path == dirpath:
672672
if mod in mods:
673673
raise AssertionError(
674-
f"While trying to load conftest path {str(conftestpath)}, "
674+
f"While trying to load conftest path {conftestpath!s}, "
675675
f"found that the module {mod} is already loaded with path {mod.__file__}. "
676676
"This is not supposed to happen. Please report this issue to pytest."
677677
)

src/_pytest/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def fixture(
12251225

12261226

12271227
@overload
1228-
def fixture( # noqa: F811
1228+
def fixture(
12291229
fixture_function: None = ...,
12301230
*,
12311231
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = ...,
@@ -1239,7 +1239,7 @@ def fixture( # noqa: F811
12391239
...
12401240

12411241

1242-
def fixture( # noqa: F811
1242+
def fixture(
12431243
fixture_function: Optional[FixtureFunction] = None,
12441244
*,
12451245
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = "function",
@@ -1673,7 +1673,7 @@ def parsefactories(
16731673
raise NotImplementedError()
16741674

16751675
@overload
1676-
def parsefactories( # noqa: F811
1676+
def parsefactories(
16771677
self,
16781678
node_or_obj: object,
16791679
nodeid: Optional[str],
@@ -1682,7 +1682,7 @@ def parsefactories( # noqa: F811
16821682
) -> None:
16831683
raise NotImplementedError()
16841684

1685-
def parsefactories( # noqa: F811
1685+
def parsefactories(
16861686
self,
16871687
node_or_obj: Union[nodes.Node, object],
16881688
nodeid: Union[str, NotSetType, None] = NOTSET,

src/_pytest/junitxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def record_func(name: str, value: object) -> None:
375375

376376
xml = request.config.stash.get(xml_key, None)
377377
if xml is not None:
378-
record_func = xml.add_global_property # noqa
378+
record_func = xml.add_global_property
379379
return record_func
380380

381381

src/_pytest/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,12 @@ def perform_collect(
726726
...
727727

728728
@overload
729-
def perform_collect( # noqa: F811
729+
def perform_collect(
730730
self, args: Optional[Sequence[str]] = ..., genitems: bool = ...
731731
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
732732
...
733733

734-
def perform_collect( # noqa: F811
734+
def perform_collect(
735735
self, args: Optional[Sequence[str]] = None, genitems: bool = True
736736
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
737737
"""Perform the collection phase for this session.

src/_pytest/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def normalize_mark_list(
406406
for mark in mark_list:
407407
mark_obj = getattr(mark, "mark", mark)
408408
if not isinstance(mark_obj, Mark):
409-
raise TypeError(f"got {repr(mark_obj)} instead of Mark")
409+
raise TypeError(f"got {mark_obj!r} instead of Mark")
410410
yield mark_obj
411411

412412

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def reportinfo(self) -> Tuple[Union["os.PathLike[str]", str], Optional[int], str
358358
# hook is not called for them.
359359
# fmt: off
360360
class _EmptyClass: pass # noqa: E701
361-
IGNORED_ATTRIBUTES = frozenset.union( # noqa: E305
361+
IGNORED_ATTRIBUTES = frozenset.union(
362362
frozenset(),
363363
# Module.
364364
dir(types.ModuleType("empty_module")),

0 commit comments

Comments
 (0)