Skip to content

Commit b84e376

Browse files
committed
More Ruff fixes
2 parents a6e9385 + 23e6771 commit b84e376

14 files changed

Lines changed: 39 additions & 52 deletions

‎.pre-commit-config.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
rev: 26.5.1
99
hooks:
1010
- id: black
11-
- repo: https://github.com/charliermarsh/ruff-pre-commit
12-
rev: "v0.0.261"
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: "v0.16.7"
1313
hooks:
14-
- id: ruff
14+
- id: ruff-check

‎pyproject.toml‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,16 @@ line-length = 120
7272

7373
[tool.ruff.lint]
7474
ignore = [
75-
# Leave enabled
76-
"BLE001", # Do not catch blind exception: `Exception`
7775
"C408", # Unnecessary `dict()` call (rewrite as a literal)
7876
"S102", # Use of `exec` detected
7977
"SIM905", # Consider using a list literal instead of `str.split`
78+
"RUF012", # Mutable default value for class attribute
8079

81-
# Possibly disable the following ones:
80+
# Possibly fix the following lints:
8281
"I001", # Import block is un-sorted or un-formatted
8382
"PLC0414", # Import alias does not rename original package
84-
"ISC004", # Unparenthesized implicit string concatenation in collection
85-
"RUF059", # Unpacked variable `matches` is never used
86-
"SIM102", # Use a single `if` statement instead of nested `if` statements
8783
"FA100", # Add `from __future__ import annotations` to simplify `typing.Optional`
8884
"D419", # Docstring is empty
89-
"TRY004", # Prefer `TypeError` exception for invalid type
90-
"RUF012", # Mutable default value for class attribute
91-
"FURB188", # Prefer `str.removesuffix()` over conditionally replacing with slice.
92-
"PYI029", # Defining `__repr__` in a stub is almost always redundant
93-
"PLR1704", # Redefining argument with the local name `s`
94-
"B020", # Loop control variable `s` overrides iterable it iterates
9585
"RUF022", # `__all__` is not sorted
96-
"B006", # Do not use mutable data structures for argument defaults
9786
"RUF023", # `SingleMatch.__slots__` is not sorted
9887
]

‎src/cutadapt/_align.pyi‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class DPMatrix:
55
n: int
66
def __init__(self, reference: str, query: str): ...
77
def set_entry(self, i: int, j: int, cost: int) -> None: ...
8-
def __str__(self) -> str: ...
98

109
class Aligner:
1110
def __init__(
@@ -18,7 +17,6 @@ class Aligner:
1817
indel_cost: int = 1,
1918
min_overlap: int = 1,
2019
): ...
21-
def __repr__(self) -> str: ...
2220
def _set_reference(self, reference: str) -> None: ...
2321
@property
2422
def dpmatrix(self) -> DPMatrix: ...
@@ -37,7 +35,6 @@ class PrefixComparer:
3735
wildcard_query: bool = False,
3836
min_overlap: int = 1,
3937
): ...
40-
def __repr__(self) -> str: ...
4138
def locate(self, query: str) -> tuple[int, int, int, int, int, int] | None: ...
4239

4340
class SuffixComparer(PrefixComparer): ...

‎src/cutadapt/adapters.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __repr__(self):
9292

9393
def __iadd__(self, other: Any):
9494
if not isinstance(other, self.__class__):
95-
raise ValueError("Cannot compare")
95+
raise TypeError("Cannot compare")
9696
if (
9797
self.max_error_rate != other.max_error_rate
9898
or self.sequence != other.sequence
@@ -172,7 +172,7 @@ def __repr__(self):
172172

173173
def __iadd__(self, other: "SingleAdapterStatistics"):
174174
if not isinstance(other, self.__class__):
175-
raise ValueError("Cannot iadd")
175+
raise TypeError("Cannot iadd")
176176
self.end += other.end
177177
self.reverse_complemented += other.reverse_complemented
178178
return self
@@ -221,7 +221,7 @@ def __repr__(self):
221221

222222
def __iadd__(self, other: "LinkedAdapterStatistics"):
223223
if not isinstance(other, self.__class__):
224-
raise ValueError("Cannot iadd")
224+
raise TypeError("Cannot iadd")
225225
self.front += other.front
226226
self.back += other.back
227227
self.reverse_complemented += other.reverse_complemented
@@ -264,7 +264,7 @@ def __repr__(self):
264264

265265
def __iadd__(self, other: "AnywhereAdapterStatistics"):
266266
if not isinstance(other, AnywhereAdapterStatistics):
267-
raise ValueError("Cannot add")
267+
raise TypeError("Cannot add")
268268
self.front += other.front
269269
self.back += other.back
270270
self.reverse_complemented += other.reverse_complemented
@@ -490,7 +490,7 @@ def removed_sequence_length(self) -> int:
490490
return len(self.sequence) - self.rstart
491491

492492

493-
def _generate_adapter_name(_start=[1]) -> str:
493+
def _generate_adapter_name(_start=[1]) -> str: # noqa: B006
494494
name = str(_start[0])
495495
_start[0] += 1
496496
return name
@@ -1415,7 +1415,7 @@ def _make_index(self) -> tuple[list[int], "AdapterIndexDict", int]:
14151415
if adapter.indels:
14161416
for s, errors, matches in edit_environment(sequence, k):
14171417
if s in index:
1418-
other_adapter, other_errors, other_matches = index[s]
1418+
other_adapter, _other_errors, other_matches = index[s]
14191419
if matches < other_matches:
14201420
continue
14211421
if other_matches == matches and s not in ambiguous:
@@ -1428,7 +1428,7 @@ def _make_index(self) -> tuple[list[int], "AdapterIndexDict", int]:
14281428
matches = n - errors
14291429
for s in hamming_sphere(sequence, errors):
14301430
if s in index:
1431-
other_adapter, other_errors, other_matches = index[s]
1431+
other_adapter, _other_errors, other_matches = index[s]
14321432
if matches < other_matches:
14331433
continue
14341434
if other_matches == matches and s not in ambiguous:

‎src/cutadapt/align.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ def naive_edit_environment(s: str, k: int) -> Iterator[str]:
8383
yield s
8484
if k == 0:
8585
return
86-
for s in naive_edit_environment(s, k - 1):
87-
n = len(s)
86+
for t in naive_edit_environment(s, k - 1):
87+
n = len(t)
8888
for ch in "ACGT":
8989
for i in range(n):
90-
prefix = s[:i] + ch
91-
yield prefix + s[i:] # insertion
92-
yield prefix + s[i + 1 :] # substitution
93-
yield s + ch # insertion into final position
90+
prefix = t[:i] + ch
91+
yield prefix + t[i:] # insertion
92+
yield prefix + t[i + 1 :] # substitution
93+
yield t + ch # insertion into final position
9494
# all deletions
9595
for i in range(n):
96-
yield s[:i] + s[i + 1 :]
96+
yield t[:i] + t[i + 1 :]
9797

9898

9999
def py_edit_environment(s: str, k: int) -> Iterator[tuple[str, int, int]]:

‎src/cutadapt/info.pyi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ class ModificationInfo:
88
cut_suffix: str
99
is_rc: bool | None
1010
def __init__(self, read: SequenceRecord) -> None: ...
11-
def __repr__(self) -> str: ...

‎src/cutadapt/json.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ def dumps(obj, indent: int = 2, _level: int = 0) -> str:
6969
+ "}"
7070
)
7171
else:
72-
raise ValueError(f"cannot serialize type {obj.__class__.__name__}")
72+
raise TypeError(f"cannot serialize type {obj.__class__.__name__}")

‎src/cutadapt/modifiers.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ def __repr__(self):
562562

563563
def __call__(self, read, info: ModificationInfo):
564564
read = read[:]
565-
if read.name.endswith(self.suffix):
566-
read.name = read.name[: -len(self.suffix)]
565+
read.name = read.name.removesuffix(self.suffix)
567566
return read
568567

569568

‎src/cutadapt/parser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def parse(cls, spec: str, adapter_type: str) -> "AdapterSpecification":
228228
if adapter_type not in ("front", "back", "anywhere"):
229229
raise ValueError("adapter_type must be front, back or anywhere")
230230

231-
spec, middle, parameters_spec = spec.partition(";")
231+
spec, _middle, parameters_spec = spec.partition(";")
232232
name, spec = cls._extract_name(spec)
233233
spec = spec.strip()
234234
parameters = parse_search_parameters(parameters_spec)

‎src/cutadapt/report.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self) -> None:
8282

8383
def __iadd__(self, other: Any):
8484
if not isinstance(other, Statistics):
85-
raise ValueError(f"Cannot add {other.__type__.__name__}")
85+
raise TypeError(f"Cannot add {other.__type__.__name__}")
8686
self.n += other.n
8787
self.read_length_statistics += other.read_length_statistics
8888

@@ -869,12 +869,14 @@ def minimal_report(stats: Statistics, time: float, gc_content: float) -> str:
869869
warning = False
870870
for which_in_pair in (0, 1):
871871
for adapter_statistics in stats.adapter_stats[which_in_pair]:
872-
if isinstance(adapter_statistics, BackAdapterStatistics):
873-
if AdjacentBaseStatistics(
872+
if (
873+
isinstance(adapter_statistics, BackAdapterStatistics)
874+
and AdjacentBaseStatistics(
874875
adapter_statistics.end.adjacent_bases
875-
).should_warn:
876-
warning = True
877-
break
876+
).should_warn
877+
):
878+
warning = True
879+
break
878880
if warning:
879881
fields[0] = "WARN"
880882
header = [

0 commit comments

Comments
 (0)