Skip to content

[chore] Stricter ruff rules - #282

Merged
fjosw merged 9 commits into
developfrom
ruff_rules_strict
Jul 6, 2026
Merged

[chore] Stricter ruff rules#282
fjosw merged 9 commits into
developfrom
ruff_rules_strict

Conversation

@fjosw

@fjosw fjosw commented Apr 20, 2026

Copy link
Copy Markdown
Owner

This PR imposes stricter ruff rules and fixes the parts which raise errors now. Main changes:

@fjosw
fjosw marked this pull request as ready for review April 20, 2026 17:49

@jkuhl-uni jkuhl-uni left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@jkuhl-uni

Copy link
Copy Markdown
Collaborator

Thank you for all the work on the code style!
I think having these slightly stricter rules makes sense. I have to familiarize myself with some of the reasoning behind the ruff rules, but I think it is a good idea overall.

@s-kuberski

Copy link
Copy Markdown
Collaborator

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 np.random.default_rng() is considered to be the proper modern solution. However, I am asking myself if this change, hidden inside the large number of other changes, could lead to unexpected behavior.

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?

fjosw added 3 commits June 18, 2026 10:46
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.
@fjosw

fjosw commented Jun 18, 2026

Copy link
Copy Markdown
Owner Author

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 ?

@jkuhl-uni

Copy link
Copy Markdown
Collaborator

Hi,
thank you again for the work.
I think moving the changes to another PR is a good idea. I haven't had time to think more about the calls within NumPy. If the current call from pyerrors is considered legacy, I hope there is an alternative that would have the same properties in regard to the seed and instantiation of the RNG as the legacy call.

@s-kuberski

Copy link
Copy Markdown
Collaborator

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:

  • in pyerrors/linalg.py, in prune, the error message for Ntrunc >= basematrix.N seems to have the inequality reversed/misleading;
  • in pyerrors/covobs.py, the error message for a non-symmetric covariance matrix is missing a closing parenthesis.

Neither is blocking from my side, these are really minor.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.toml and 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.

Comment thread pyerrors/misc.py
Comment on lines +123 to 127
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])
Comment thread pyerrors/input/utils.py
Comment on lines +135 to 139
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] + ','
@fjosw
fjosw merged commit e72949b into develop Jul 6, 2026
11 checks passed
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.

4 participants