Skip to content

Commit

Permalink
(chore): Update to Ruff 0.9 and add EM lints (#1825)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Jan 16, 2025
1 parent cceaa75 commit 9120c4d
Show file tree
Hide file tree
Showing 36 changed files with 311 additions and 241 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
args: ["--fix"]
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ def gen_indexer(adata, dim, index_kind, ratio):
index_kinds = {"slice", "intarray", "boolarray", "strarray"}

if index_kind not in index_kinds:
raise ValueError(
f"Argument 'index_kind' must be one of {index_kinds}. Was {index_kind}."
)
msg = f"Argument 'index_kind' must be one of {index_kinds}. Was {index_kind}."
raise ValueError(msg)

axis = dimnames.index(dim)
subset = [slice(None), slice(None)]
Expand Down
4 changes: 3 additions & 1 deletion ci/scripts/min-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def extract_min_deps(

# If we are referring to other optional dependency lists, resolve them
if req.name == project_name:
assert req.extras, f"Project included itself as dependency, without specifying extras: {req}"
assert req.extras, (
f"Project included itself as dependency, without specifying extras: {req}"
)
for extra in req.extras:
extra_deps = pyproject["project"]["optional-dependencies"][extra]
dependencies += map(Requirement, extra_deps)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ docstring-code-format = true
[tool.ruff.lint]
select = [
"E", # Error detected by Pycodestyle
"EM", # Traceback-friendly error messages
"F", # Errors detected by Pyflakes
"FBT", # Boolean positional arguments
"W", # Warning detected by Pycodestyle
"PLW", # Pylint
"UP", # pyupgrade
"I", # isort
"TCH", # manage type checking blocks
"TC", # manage type checking blocks
"TID", # Banned imports
"ICN", # Follow import conventions
"PTH", # Pathlib instead of os.path
Expand Down
5 changes: 2 additions & 3 deletions src/anndata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
try:
from ._version import __version__
except ModuleNotFoundError:
raise RuntimeError(
"anndata is not correctly installed. Please install it, e.g. with pip."
)
msg = "anndata is not correctly installed. Please install it, e.g. with pip."
raise RuntimeError(msg)

# Allowing notes to be added to exceptions. See: https://github.com/scverse/anndata/issues/868
import sys
Expand Down
3 changes: 2 additions & 1 deletion src/anndata/_core/aligned_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def _gen_dataframe_1d(
attr: Literal["obs", "var"],
length: int | None = None,
):
raise ValueError(f"Cannot convert {type(anno)} to {attr} DataFrame")
msg = f"Cannot convert {type(anno)} to {attr} DataFrame"
raise ValueError(msg)


def _mk_df_error(
Expand Down
5 changes: 2 additions & 3 deletions src/anndata/_core/aligned_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def __setitem__(self, key: str, value: Value) -> None:

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

0 comments on commit 9120c4d

Please sign in to comment.