Skip to content

STY: ignore all existing violations to rule PLR0917 and upgrade ruff to 0.16.x - #20194

Open
neutrinoceros wants to merge 6 commits into
astropy:mainfrom
neutrinoceros:sty/plr0917
Open

STY: ignore all existing violations to rule PLR0917 and upgrade ruff to 0.16.x#20194
neutrinoceros wants to merge 6 commits into
astropy:mainfrom
neutrinoceros:sty/plr0917

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

Close #20113

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

Good catch, thank you !
This rule alone has about 1000 violations so I'll keep it ignored for now.

@larrybradley larrybradley left a comment

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.

Approve for convolution, stats, and visualization. Overall, it looks good.

@github-project-automation github-project-automation Bot moved this from Triage to Reviewer approved in Cosmology, the Expansion Aug 4, 2026
@dhomeier

dhomeier commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Out of curiosity, do you know what the difference is between just adding _ignore_s and using the @typing.override Ruff suggests for some cases?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I'm not aware of this suggestion nor did I see it at any point going through a limited subset of ruff's diagnostics. Could you give an example of it ?

@nstarman

nstarman commented Aug 4, 2026

Copy link
Copy Markdown
Member

Can you add PLR0917 to ignore list of **/tests/* since pytest fixtures appear to static analyzers as positional arguments, but pytest handles them as kwargs. That should reduce the number of ignore comments by a lot.

@dhomeier

dhomeier commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I'm not aware of this suggestion nor did I see it at any point going through a limited subset of ruff's diagnostics. Could you give an example of it ?

I haven't checked here, but this is e.g. what the glue-core auto-update brings up. Apparently only applies to functions redefined in subclasses.

@neutrinoceros

neutrinoceros commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Oh I see.
As per the docs

This rule exempts methods decorated with @typing.override. Changing the signature of a subclass method may cause type checkers to complain about a violation of the Liskov Substitution Principle if it means that the method now incompatibly overrides a method defined on a superclass. Explicitly decorating an overriding method with @override signals to Ruff that the method is intended to override a superclass method and that a type checker will enforce that it does so; Ruff therefore knows that it should not enforce rules about methods having too many arguments.

Comment thread astropy/units/quantity_helper/erfa.py
Comment thread astropy/units/quantity_helper/function_helpers.py Outdated
Comment thread .ruff.toml
"C901", # McCabeComplexity

# flake8-copyright
"CPY001", # missing-copyright-notice

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.

When / if this ever has an auto fix I'd be in favor of adding that to Astropy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was wondering if it could be useful e.g. to keep LLM agents from ingesting the code. Probably not that they'd really care...

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.

🤷 Probably not, but it might help LLMs attribute code suggestions, particularly if the copyright statement said something like "a good faith effort to attribute code should be made."
Then when someone asks for a function that does something the LLM might in-line a comment like

def function():
    # based on Astropy implementation.

Which is useful both for us and them (since it might be possible / better to import and use an existing astropy function).

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.

# ruff: file-ignore[PLR0917] here too.

@nstarman nstarman left a comment

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.

cosmology and units LGTM.

@pllim

pllim commented Aug 4, 2026

Copy link
Copy Markdown
Member

I thought we were only going to modify pyproject.toml but okay...

@saimn saimn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t think this comment is of any use whatsoever, arguments won't disappear in the near or far future, so just add a global exclude please.

ruff: ignore[PLR0917] historical API

@github-project-automation github-project-automation Bot moved this from Reviewer approved to Review in progress in Cosmology, the Expansion Aug 4, 2026
@dhomeier

dhomeier commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I don’t think this comment is of any use whatsoever, arguments won't disappear in the near or far future, so just add a global exclude please.

ruff: ignore[PLR0917] historical API

But the idea discussed was to enable it in the future for newly added functions. Maybe "legacy" or "pre-existing" API would be a better term?

@dhomeier

dhomeier commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

In case not all subpackage maintainers come to an agreement on the ignores, should those get a per-package exception in pyproject.toml or .ruff.toml?
Or, as an alternative compromise, have you checked how many violations remain with max-positional-args increased to 7 or 8? Seems a good deal of definitions already explicitly using the posargs, *, namedargs syntax have that many.
(Just checked locally; for 7: 116 out of 305 remaining, for 8: 77)

@neutrinoceros

neutrinoceros commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Here's what I got on current main

max-positional-args violations
0 8928
1 4223
2 2008
3 999
4 551
5 (default) 305
6 190
7 116
8 77
... ...
16 3

so the number of violations is roughly divided by 2 for each additional slot allowed-positional up to 5, then it goes off more slowly. I personally think we should aim for 3 to 4 for new functions, and that 5 is a very decent default for a large and old code base such as astropy.

@dhomeier

Copy link
Copy Markdown
Contributor

The old code base is not really a concern here since the existing functions will remain exempt anyway. But I also think 3-5 is a good recommendation for new functions in general. And to any new function where a larger number seems justified, the comment could still be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review in progress

Development

Successfully merging this pull request may close these issues.

MNT: upgrading ruff to 0.16.x

8 participants