Skip to content

Commit f9f06db

Browse files
committed
Backport PR #1825: (chore): Update to Ruff 0.9 and add EM lints
1 parent 422fb77 commit f9f06db

35 files changed

Lines changed: 310 additions & 239 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.8.1
3+
rev: v0.9.1
44
hooks:
55
- id: ruff
6-
types_or: [python, pyi, jupyter]
76
args: ["--fix"]
87
- id: ruff-format
9-
types_or: [python, pyi, jupyter]
108
- repo: https://github.com/pre-commit/mirrors-prettier
119
rev: v4.0.0-alpha.8
1210
hooks:

benchmarks/benchmarks/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ def gen_indexer(adata, dim, index_kind, ratio):
6363
index_kinds = {"slice", "intarray", "boolarray", "strarray"}
6464

6565
if index_kind not in index_kinds:
66-
raise ValueError(
67-
f"Argument 'index_kind' must be one of {index_kinds}. Was {index_kind}."
68-
)
66+
msg = f"Argument 'index_kind' must be one of {index_kinds}. Was {index_kind}."
67+
raise ValueError(msg)
6968

7069
axis = dimnames.index(dim)
7170
subset = [slice(None), slice(None)]

ci/scripts/min-deps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def extract_min_deps(
7171

7272
# If we are referring to other optional dependency lists, resolve them
7373
if req.name == project_name:
74-
assert req.extras, f"Project included itself as dependency, without specifying extras: {req}"
74+
assert req.extras, (
75+
f"Project included itself as dependency, without specifying extras: {req}"
76+
)
7577
for extra in req.extras:
7678
extra_deps = pyproject["project"]["optional-dependencies"][extra]
7779
dependencies += map(Requirement, extra_deps)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ docstring-code-format = true
171171
[tool.ruff.lint]
172172
select = [
173173
"E", # Error detected by Pycodestyle
174+
"EM", # Traceback-friendly error messages
174175
"F", # Errors detected by Pyflakes
175176
"W", # Warning detected by Pycodestyle
176177
"PLW", # Pylint
177178
"UP", # pyupgrade
178179
"I", # isort
179-
"TCH", # manage type checking blocks
180+
"TC", # manage type checking blocks
180181
"TID", # Banned imports
181182
"ICN", # Follow import conventions
182183
"PTH", # Pathlib instead of os.path

src/anndata/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
try:
1616
from ._version import __version__
1717
except ModuleNotFoundError:
18-
raise RuntimeError(
19-
"anndata is not correctly installed. Please install it, e.g. with pip."
20-
)
18+
msg = "anndata is not correctly installed. Please install it, e.g. with pip."
19+
raise RuntimeError(msg)
2120

2221
# Allowing notes to be added to exceptions. See: https://github.com/scverse/anndata/issues/868
2322
import sys

src/anndata/_core/aligned_df.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def _gen_dataframe_1d(
8282
attr: Literal["obs", "var"],
8383
length: int | None = None,
8484
):
85-
raise ValueError(f"Cannot convert {type(anno)} to {attr} DataFrame")
85+
msg = f"Cannot convert {type(anno)} to {attr} DataFrame"
86+
raise ValueError(msg)
8687

8788

8889
def _mk_df_error(

src/anndata/_core/aligned_mapping.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ def __setitem__(self, key: str, value: Value) -> None:
175175

176176
def __delitem__(self, key: str) -> None:
177177
if key not in self:
178-
raise KeyError(
179-
"'{key!r}' not found in view of {self.attrname}"
180-
) # Make sure it exists before bothering with a copy
178+
msg = f"{key!r} not found in view of {self.attrname}"
179+
raise KeyError(msg) # Make sure it exists before bothering with a copy
181180
warnings.warn(
182181
f"Removing element `.{self.attrname}['{key}']` of view, "
183182
"initializing view as actual.",

0 commit comments

Comments
 (0)