[chore] Stricter ruff rules - #282
Conversation
|
Thank you for all the work on the code style! |
|
Hi! Thanks for taking the time to implement this! I am still in the process of looking through the changes. I was wondering about the change of the handling of random numbers. I understand that switching to As I understand it, changing the numpy random seed will not affect the state of the random number generator anymore, right? So there won't be any way to fix the seed in the random number generator in the future, when its initialization is hidden in the module. Could this lead to problems? |
Restore use of the global np.random state in pseudo_Obs (misc.py) and the prior id generation (fits.py), keeping seed behavior unchanged. The switch to a module-local generator is out of scope for this lint-focused PR.
The RNG migration was reverted to keep np.random.seed() behavior, so add per-line noqa: NPY002 on the three legacy np.random calls instead of the Generator API.
|
After quite some time I had another look at this PR. I agree with leaving the RNG changes out of this PR and potentially do them separately or not at all. I removed the rng changes from the diff. Could you review the changes that are left @s-kuberski @jkuhl-uni ? |
|
Hi, |
|
Thanks for the adaption! This looks good to me and can be merged from my side. There are only two very small things we might still want to fix before merging, that I noticed in lines that were touched in this pull request:
Neither is blocking from my side, these are really minor. |
There was a problem hiding this comment.
Pull request overview
This PR tightens the repository’s Ruff linting configuration and updates code/tests to satisfy the stricter rules, including safer iteration patterns (zip(..., strict=True)), removal of mutable default arguments, and modernization away from printf-style formatting.
Changes:
- Added/expanded Ruff configuration in
pyproject.tomland updated CI/docs to use Ruff instead of flake8. - Refactored multiple modules to address new lint violations (e.g., strict zip, f-strings/formatting, loop-variable hygiene, safer exception chaining, stacklevel on warnings).
- Added regression tests covering strict-zip mismatches and unhashability expectations for
Corr/CObs, plus an integration-derivative closure binding test.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/obs_test.py | Adds tests for Obs mismatched lengths, fractional N_sigma formatting in details(), and CObs unhashability. |
| tests/integrate_test.py | Adds a regression test ensuring per-parameter derivatives don’t collapse due to a closure-binding bug. |
| tests/correlators_test.py | Adds tests ensuring Corr padding default isn’t shared and Corr is unhashable. |
| setup.py | Removes flake8 from test extras (Ruff is now the lint tool). |
| pyproject.toml | Introduces Ruff target version and stricter lint rule selection/ignores. |
| pyerrors/special.py | Reformats imports/__all__ for lint compliance and readability. |
| pyerrors/roots.py | Minor formatting cleanup (blank line). |
| pyerrors/obs.py | Enforces strict zips, modernizes formatting, adds warning stacklevels, binds closure variables safely, and updates various small lint-driven refactors. |
| pyerrors/mpm.py | Normalizes import ordering. |
| pyerrors/misc.py | Lint-driven refactors; affects pseudo_Obs() implementation. |
| pyerrors/linalg.py | Normalizes imports and addresses unused loop variables / strict zip. |
| pyerrors/integrate.py | Fixes closure binding for i inside a vectorized lambda and normalizes imports. |
| pyerrors/input/utils.py | Addresses unused os.walk variables and improves last-line tracking in param files. |
| pyerrors/input/sfcf.py | Removes mutable default args, strict-zips name/type pairs, improves exception chaining, adds warning stacklevels. |
| pyerrors/input/pandas.py | Import ordering tweaks and adds stacklevel to warnings. |
| pyerrors/input/openQCD.py | Import cleanup, warning stacklevel, safer defaults, and small formatting refactors. |
| pyerrors/input/misc.py | Import ordering tweaks and warning stacklevel. |
| pyerrors/input/json.py | Import ordering cleanup and conversion of printf-style formatting to f-strings. |
| pyerrors/input/hadrons.py | Removes mutable default args and strict-zips correlated iterables. |
| pyerrors/input/dobs.py | Removes mutable default args and converts many format strings to f-strings. |
| pyerrors/input/bdio.py | Refactors loops/formatting, strict-zips correlated iterables, and updates tuple construction. |
| pyerrors/fits.py | Import ordering, exception chaining, closure binding fixes, strict zips, and warning stacklevels. |
| pyerrors/dirac.py | Removes an extra blank line. |
| pyerrors/covobs.py | Improves exception formatting (fixes malformed message). |
| pyerrors/correlators.py | Removes mutable default args, adds warning stacklevel, makes Corr unhashable, and includes small lint refactors. |
| pyerrors/init.py | Reorders imports/exports to satisfy linting and style expectations. |
| CONTRIBUTING.md | Updates contributor guidance from flake8 to Ruff (including commands). |
| .github/workflows/ruff.yml | Updates Ruff workflow action versions. |
| .github/workflows/release.yml | Updates checkout action version. |
| .github/workflows/pytest.yml | Updates checkout action version. |
| .github/workflows/flake8.yml | Removes flake8 workflow. |
| .github/workflows/examples.yml | Updates checkout action version. |
| .github/workflows/docs.yml | Updates checkout action version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| deltas = [np.random.normal(0.0, dvalue * np.sqrt(samples), samples)] # noqa: NPY002 | ||
| deltas -= np.mean(deltas) | ||
| deltas *= dvalue / np.sqrt((np.var(deltas) / samples)) / np.sqrt(1 + 3 / samples) | ||
| deltas *= dvalue / np.sqrt(np.var(deltas) / samples) / np.sqrt(1 + 3 / samples) | ||
| deltas += value | ||
| res = Obs(deltas, [name]) |
| last_line = '' | ||
| for line in fp: | ||
| pass | ||
| last_line = line | ||
| last_line = line | ||
| if last_line.split()[2] != param_hash: | ||
| rep_nums += file.split("_")[1] + ',' |
This PR imposes stricter ruff rules and fixes the parts which raise errors now. Main changes: