Skip to content

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

Merged
flying-sheep merged 4 commits into
mainfrom
pa/ruff-0-9-em
Jan 16, 2025
Merged

(chore): Update to Ruff 0.9 and add EM lints#1825
flying-sheep merged 4 commits into
mainfrom
pa/ruff-0-9-em

Conversation

@flying-sheep
Copy link
Copy Markdown
Member

@flying-sheep flying-sheep commented Jan 13, 2025

Since Ruff 0.9 touches a bunch of Exception instantiations, I thought adding the EM lints now is a good time. See #1241

The coverage issues are expected as we don’t test some just-in-case exception raisings. So a PR touching many spots that involve instantiating exceptions will have low coverage.

@flying-sheep flying-sheep mentioned this pull request Jan 13, 2025
19 tasks
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 37.96992% with 165 lines in your changes missing coverage. Please review.

Project coverage is 83.64%. Comparing base (cceaa75) to head (bd0faf0).
Report is 69 commits behind head on main.

Files with missing lines Patch % Lines
src/anndata/_core/anndata.py 32.30% 44 Missing ⚠️
src/anndata/experimental/merge.py 16.66% 20 Missing ⚠️
src/anndata/_core/merge.py 33.33% 16 Missing ⚠️
src/anndata/_core/sparse_dataset.py 50.00% 12 Missing ⚠️
src/anndata/tests/helpers.py 0.00% 11 Missing ⚠️
...anndata/experimental/multi_files/_anncollection.py 0.00% 8 Missing ⚠️
src/anndata/utils.py 42.85% 8 Missing ⚠️
src/anndata/_core/file_backing.py 0.00% 6 Missing ⚠️
src/anndata/_core/index.py 66.66% 6 Missing ⚠️
src/anndata/_io/read.py 40.00% 6 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   87.09%   83.64%   -3.46%     
==========================================
  Files          40       40              
  Lines        6138     6267     +129     
==========================================
- Hits         5346     5242     -104     
- Misses        792     1025     +233     
Files with missing lines Coverage Δ
src/anndata/_core/aligned_mapping.py 93.44% <100.00%> (+0.02%) ⬆️
src/anndata/_io/specs/lazy_methods.py 97.80% <100.00%> (+0.04%) ⬆️
src/anndata/_io/write.py 77.77% <100.00%> (+0.24%) ⬆️
src/anndata/_settings.py 94.11% <100.00%> (ø)
src/anndata/io.py 100.00% <ø> (ø)
src/anndata/logging.py 50.00% <ø> (ø)
src/anndata/__init__.py 90.62% <0.00%> (-2.93%) ⬇️
src/anndata/_core/aligned_df.py 95.65% <0.00%> (-2.13%) ⬇️
src/anndata/_core/views.py 85.02% <50.00%> (-6.09%) ⬇️
src/anndata/_io/h5ad.py 92.68% <80.00%> (-0.32%) ⬇️
... and 16 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@flying-sheep flying-sheep changed the title Update to Ruff 0.9 and add EM lints (chore): Update to Ruff 0.9 and add EM lints Jan 13, 2025
Copy link
Copy Markdown
Member Author

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

All code changes in this PR are mechanical, except for the obvious (add EM to ruff config, bump Ruff version) and the ones noted below:

Comment thread .pre-commit-config.yaml
rev: v0.9.1
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
Copy link
Copy Markdown
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

Comment thread pyproject.toml
Comment on lines -181 to +182
"TCH", # manage type checking blocks
"TC", # manage type checking blocks
Copy link
Copy Markdown
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

Comment on lines -178 to +179
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I spotted this error: There was an f missing, so this error message was pretty useless

Comment thread src/anndata/_settings.py
validate(default_value)
except (ValueError, TypeError) as e:
add_note(e, f"for option {repr(option)}")
add_note(e, f"for option {option!r}")
Copy link
Copy Markdown
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.

I changed this to use the format specifier !r instead of repr. (and did the same ~2 other times)

Comment thread tests/test_layers.py
Comment on lines -11 to +12
from anndata import AnnData, ImplicitModificationWarning, read_h5ad, read_loom
from anndata import AnnData, ImplicitModificationWarning, read_h5ad
from anndata.io import read_loom
Copy link
Copy Markdown
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.

Independent driveby fix, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants