Skip to content

Start enforcing the Ruff RUF rules#251

Merged
avalentino merged 1 commit into
liberfa:mainfrom
eerovaher:enforce-RUF
May 20, 2026
Merged

Start enforcing the Ruff RUF rules#251
avalentino merged 1 commit into
liberfa:mainfrom
eerovaher:enforce-RUF

Conversation

@eerovaher
Copy link
Copy Markdown
Contributor

@eerovaher eerovaher commented May 18, 2026

I am configuring Ruff to enforce its RUF rules. There were two kinds of RUF violations that had to be fixed.

docs/conf.py contained non-ASCII characters that are visually indistinguishable or almost indistinguishable from ASCII characters. Personally I am not opposed to using non-ASCII characters when they improve readability (e.g. writing α instead of alpha), but visually indistinguishable characters cannot possibly do that.

In erfa/tests/test_erfa.py Ruff pointed out several unused unpacked variables. If a pyerfa Python wrapper function returns a tuple it will have named attributes, so if only one or two values are needed then unpacking the tuple does not improve readability. I've rewritten the test in question as two separate parametrized tests.

Comment thread erfa/tests/test_erfa.py
aob, zob, hob, dob, rob, eo = erfa.atco13(
ra[:, None, None], dec[None, :, None], 0.0, 0.0, 0.0, 0.0, jd[None, None, :],
0.0, 0.0, 0.0, np.pi/4.0, 0.0, 0.0, 0.0, 1014.0, 0.0, 0.0, 0.5)
(aob.shape) == (5, 4, 121)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no assert here, so this was a useless comparison. The Ruff rule B015 (useless-comparison) would guard against mistakes like that, but we haven't turned on the B rules yet.

Comment thread erfa/tests/test_erfa.py
[
pytest.param(0.0, 0.0, 2456855.5, (), id="scalar"),
pytest.param(
0.0, 0.0, np.linspace(2456855.5, 2456856.5, 5), (5,), id="simple array"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This does not look like the original one
Do I miss something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made the arrays smaller because I didn't see the point in forcing the tests to run with larger arrays, but the tests are still checking that the output shape is correct. I did also change the range of jd values to shorten setup, but that shouldn't matter because with or without my patch the asserts here only care about the shape of the outputs, not about the values within.

@avalentino avalentino merged commit d740092 into liberfa:main May 20, 2026
28 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.

2 participants