Enable eight previously-ignored ruff lint rules - #62
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First pass at trimming the
[tool.ruff.lint] ignorelist inpyproject.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 --statisticsto get the real violation count behind each ignored rule, then picking the ones whose fixes are mechanical and carry no behavior change.Rules enabled
b61771eC408unnecessary-collection-calldict(...)calls rewritten as dict literalsb61771eTRY201verbose-raiseraise einsideexceptblocks replaced with bareraise, plus the 5 now-unusedas ebindings thatF841flagged as a result4d3f9feRSE102unnecessary-paren-on-raise-exceptionraise click.Abort()→raise click.Abort2c2fa15SIM101duplicate-isinstance-callisinstance(x, A) or isinstance(x, B)pairs merged into tuple forma682718FURB110if-exp-instead-of-or-operatoros.path.dirname(x) if os.path.dirname(x) else "."→os.path.dirname(x) or ".", which also avoids callingdirnametwice56a6897RUF005collection-literal-concatenationc657d63UP030format-literalsstr.format()calls invalidate_dem.pyswitched from explicit positional indices to implicit ones3d2e7c2EXE001shebang-not-executableNotes
EXE001— the seven affected modules are not executed directly: the package installs a singleivertconsole 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#!python3line inutils/split_dem.py, which was not a valid interpreter path and would have failed if the file were ever executed directly.SIM101— thedatetimecheck inicesat2_database_v2.pyis kept asisinstance(date, (datetime.datetime, datetime.date)). Sincedatetime.datetimesubclassesdatetime.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, andstrict=Trueconverts today's silent truncation into aValueError. That deserves its own pass.Verification
ruff check srcandruff format --check srcpass, andprek run --all-filespasses, at every commit in the branch.ivert --helpruns, and all touched modules import cleanly. Two modules could only be checked withpy_compilefor environment reasons unrelated to this branch:validate_dem.pyneedstransformez, which is not installed locally, andplot_results_slope_centrality.pyimports a nonexistentimport_parent_dirmodule (pre-existing onmain, confirmed by checking outmainand reproducing the same failure)..format()calls and unpacking expressions were spot-checked to produce identical output.pytestis 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 genuineos.path→pathlibrefactor rather than a sweep. Other sizable groups still ignored includeANN*,ERA001,E501,T201, andEM101/EM102.Part of #40.