Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore): Update to Ruff 0.9 and add EM lints #1825

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has since become the default for Ruff, so we can remove it

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
Comment on lines -181 to +182
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been renamed by Ruff

"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)

Check warning on line 19 in src/anndata/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/anndata/__init__.py#L18-L19

Added lines #L18 - L19 were not covered by tests

# 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 @@
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)

Check warning on line 86 in src/anndata/_core/aligned_df.py

View check run for this annotation

Codecov / codecov/patch

src/anndata/_core/aligned_df.py#L85-L86

Added lines #L85 - L86 were not covered by tests


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
Loading