Enable nine more previously-ignored ruff lint rules - #63
Merged
Conversation
Remove C404, PERF401, RET503, RUF012, RUF013, RUF059, SIM118, SIM212 and UP031 from the ruff lint ignore list and fix the ten resulting errors: - C404: build a dict comprehension directly instead of dict([(k, v), ...]). - PERF401: replace an append loop with a list comprehension. - RET503: restructure _fmt_size() so the final return is reachable. The loop could never fall through, so ruff's literal fix would have added dead code; dropping 'TB' from the loop and returning it explicitly is equivalent for every input. - RUF012: annotate a mutable class attribute as ClassVar. - RUF013: spell an implicit Optional argument as 'list | None'. - RUF059: rename an unused unpacked variable to _base. Two other call sites unpack the same expression but do use 'base'; only this one was flagged. - SIM118: iterate a config section directly instead of via .keys(). - SIM212: rewrite 'None if not datadir else datadir' as 'datadir or None'. Ruff suggests the ternary form, but that would trip FURB110. - UP031: replace two percent-format strings with f-strings. 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.
Second pass at trimming the
[tool.ruff.lint] ignorelist inpyproject.toml, following #62. This removes nine more rules and fixes the ten errors they raise. The ignore list goes from 130 to 121 entries.As before, rules were chosen by running
ruff check src --extend-select ALL --statisticsto get the real violation count behind each ignored rule, then picking those whose fixes are mechanical and carry no behavior change.Rules enabled
C404unnecessary-list-comprehension-dictdict([(k, v), ...])rewritten as a dict comprehensionPERF401manual-list-comprehensionRET503implicit-return_fmt_size()restructured so its final return is reachableRUF012mutable-class-defaultClassVar[dict[str, str]]RUF013implicit-optionalclasses: list = Nonespelled asclasses: list | None = NoneRUF059unused-unpacked-variablebaserenamed to_baseSIM118in-dict-keys.keys()SIM212if-expr-with-twisted-armsNone if not datadir else datadir→datadir or NoneUP031printf-string-formattingNotes
RET503—_fmt_size()iterates("B", "KB", "MB", "GB", "TB")and returns whennbytes < 1024 or unit == "TB", so the loop can never fall through and ruff's literal fix would have appended an unreachablereturn None. Instead the loop now covers("B", "KB", "MB", "GB")with theTBcase returned explicitly afterward. The two forms were compared across 11 magnitudes from0to petabyte-scale and produce identical output for every input.RUF059— the linebase, ext = os.path.splitext(results_dataframe_file)appears three times invalidate_dem.py(lines 967, 1327, 1731). The first two usebaseon the following line; only line 1731 leaves it unused, and only that one is renamed.SIM212— ruff's suggested fix isdatadir if datadir else None, which would immediately violateFURB110(enabled in #62). Theorform satisfies both rules.RUF012— addsfrom typing import ClassVartoicesat2_database_v2.py. The annotation is purely declarative; the attribute remains an ordinary class-level dict at runtime.B905(zip-without-explicit-strict, 15 sites) is again deliberately left out. It is the one remaining low-count rule that 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. It deserves its own pass.Verification
ruff check src,ruff format --check src, andprek run --all-filesall pass.ivert --helpandivert optionsrun; all touched modules import cleanly._fmt_sizeold vs. new compared across 11 input magnitudes (no mismatches);list(section) == list(section.keys())confirmed against the real config for theSIM118change;SIM212equivalence checked for"",None, a path, and"."; theClassVardict confirmed still readable with correct values; both rewrittenValueErrormessages confirmed to render as before.py_compile, for 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).pytestis not installed in the local environment, so the test suite was not run.Remaining work
Still one step toward #40, not the whole thing. The largest remaining block is the
PTH*cluster (~380 hits across 20 rules), a genuineos.path→pathlibrefactor rather than a sweep. Other sizable groups still ignored includeANN*,ERA001,E501,T201, andEM101/EM102.Part of #40.