Skip to content

Enable eight previously-ignored ruff lint rules - #62

Merged
mmacferrin merged 7 commits into
mainfrom
ruff-unignore-rules-v1
Jul 28, 2026
Merged

Enable eight previously-ignored ruff lint rules#62
mmacferrin merged 7 commits into
mainfrom
ruff-unignore-rules-v1

Conversation

@mmacferrin

Copy link
Copy Markdown
Collaborator

First pass at trimming the [tool.ruff.lint] ignore list in pyproject.toml, per #40. This removes eight rules from the ignore list and fixes every error they raise. The ignore list goes from 138 to 130 entries.

Rules were chosen by running ruff check src --extend-select ALL --statistics to get the real violation count behind each ignored rule, then picking the ones whose fixes are mechanical and carry no behavior change.

Rules enabled

Commit Rule Change
b61771e C408 unnecessary-collection-call 20 dict(...) calls rewritten as dict literals
b61771e TRY201 verbose-raise 5 raise e inside except blocks replaced with bare raise, plus the 5 now-unused as e bindings that F841 flagged as a result
4d3f9fe RSE102 unnecessary-paren-on-raise-exception 2 raise click.Abort()raise click.Abort
2c2fa15 SIM101 duplicate-isinstance-call 2 isinstance(x, A) or isinstance(x, B) pairs merged into tuple form
a682718 FURB110 if-exp-instead-of-or-operator 2 os.path.dirname(x) if os.path.dirname(x) else "."os.path.dirname(x) or ".", which also avoids calling dirname twice
56a6897 RUF005 collection-literal-concatenation 2 sequence concatenations rewritten as unpacking
c657d63 UP030 format-literals 5 str.format() calls in validate_dem.py switched from explicit positional indices to implicit ones
3d2e7c2 EXE001 shebang-not-executable 7 vestigial shebang lines removed

Notes

EXE001 — the seven affected modules are not executed directly: the package installs a single ivert console script (ivert = "ivert.cli:ivert_cli"), and everything else is imported or run through the interpreter. Removing the shebangs keeps all file modes at 644 rather than adding execute bits to library modules. It also retires the #!python3 line in utils/split_dem.py, which was not a valid interpreter path and would have failed if the file were ever executed directly.

SIM101 — the datetime check in icesat2_database_v2.py is kept as isinstance(date, (datetime.datetime, datetime.date)). Since datetime.datetime subclasses datetime.date, the second member is technically redundant, but preserving it keeps this a pure lint fix rather than a semantic one.

B905 (zip-without-explicit-strict, 15 sites) was considered and deliberately left out. Unlike the rules above it is not mechanical — each call site needs a decision about whether the zipped iterables are guaranteed equal-length, and strict=True converts today's silent truncation into a ValueError. That deserves its own pass.

Verification

  • ruff check src and ruff format --check src pass, and prek run --all-files passes, at every commit in the branch.
  • ivert --help runs, and all touched modules import cleanly. Two modules could only be checked with py_compile for environment reasons unrelated to this branch: validate_dem.py needs transformez, which is not installed locally, and plot_results_slope_centrality.py imports a nonexistent import_parent_dir module (pre-existing on main, confirmed by checking out main and reproducing the same failure).
  • Module docstrings confirmed intact after the shebang removals.
  • The rewritten .format() calls and unpacking expressions were spot-checked to produce identical output.

pytest is not installed in the local environment, so the test suite was not run.

Remaining work

This is one step toward #40, not the whole thing. The largest remaining block is the PTH* cluster (~380 hits across 20 rules), which is a genuine os.pathpathlib refactor rather than a sweep. Other sizable groups still ignored include ANN*, ERA001, E501, T201, and EM101/EM102.

Part of #40.

Remove C408 (unnecessary-collection-call) and TRY201 (verbose-raise) from
the ruff lint ignore list in pyproject.toml and fix the resulting errors:

- Rewrite 20 dict() calls as dict literals.
- Replace 5 'raise e' statements inside except blocks with a bare 'raise',
  dropping the now-unused 'as e' bindings.

Part of #40.
Remove RSE102 (unnecessary-paren-on-raise-exception) from the ruff lint
ignore list and drop the parentheses from two 'raise click.Abort()'
statements.

Part of #40.
Remove SIM101 (duplicate-isinstance-call) from the ruff lint ignore list
and merge two pairs of 'isinstance(x, A) or isinstance(x, B)' checks into
single tuple-form isinstance calls.

Part of #40.
Remove FURB110 (if-exp-instead-of-or-operator) from the ruff lint ignore
list and rewrite two 'os.path.dirname(x) if os.path.dirname(x) else "."'
ternaries as 'os.path.dirname(x) or "."', which also avoids calling
dirname twice.

Part of #40.
Remove RUF005 (collection-literal-concatenation) from the ruff lint
ignore list and rewrite two sequence concatenations as unpacking.

Part of #40.
Remove UP030 (format-literals) from the ruff lint ignore list and switch
five str.format() calls in validate_dem.py from explicit positional
indices to implicit ones. Format specs and argument order are unchanged,
so the rendered strings are identical.

Part of #40.
Remove EXE001 (shebang-not-executable) from the ruff lint ignore list and
drop the vestigial shebang lines from seven modules. None of these are
executed directly: the package installs a single 'ivert' console script,
and the modules are imported or run via the interpreter. This also
retires the invalid '#!python3' line in utils/split_dem.py.

Part of #40.
@mmacferrin
mmacferrin merged commit 469919f into main Jul 28, 2026
3 checks passed
@mmacferrin
mmacferrin deleted the ruff-unignore-rules-v1 branch July 28, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant