Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: lint: enable UP rules #19516

Merged
merged 3 commits into from Nov 21, 2023
Merged

MAINT: lint: enable UP rules #19516

merged 3 commits into from Nov 21, 2023

Conversation

lucascolley
Copy link
Member

@lucascolley lucascolley commented Nov 13, 2023

Reference issue

#18353 (comment)

What does this implement/fix?

  • The UP rules are enabled in the linter
  • All existing violations are cleaned up

Quoting @stefanv :

The Ruff PyUpgrade rules ensure that SciPy uses modern Python constructs that work with all support Python versions.
While the linter only runs on files touched in any given PR, we have the option to apply these rules wholesale each time we drop support for another version of Python.
This keeps our code current, at low cost to maintainers.

Additional information

The vast majority of these changes were made automatically by Ruff's --fix, with the rest (changing from Union typing and to yield from) made by me.

Due to the automatic fixes, further (minor) style cleanups are possible here, but I don't know if they're worth the effort (or worth delaying this PR for).

The blame ignore will be added once this is ready.

@stefanv
Copy link
Member

stefanv commented Nov 13, 2023

If there is agreement on this change, we should add a commit with an entry in .git-blame-ignore-revs, and then merge (not squash merge) the PR.

@lucascolley
Copy link
Member Author

If there is agreement on this change, we should add a commit with an entry in .git-blame-ignore-revs, and then merge (not squash merge) the PR.

Yes, I didn't yet in anticipation of a force push (which was immediately necessary since I forgot to mamba upgrade ruff). Perhaps there will be no force pushes from now on but no harm in holding off for a little longer.

@lucascolley
Copy link
Member Author

CI is green (apart from the broken docs build). I've noticed some formatting issues (multiline strings off by 1 space, closing brackets on a new line). These will probably have to be looked at manually unfortunately.

@j-bowhay j-bowhay added the maintenance Items related to regular maintenance tasks label Nov 14, 2023
@ilayn
Copy link
Member

ilayn commented Nov 14, 2023

These will probably have to be looked at manually unfortunately.

It would difficult to catch them later if we lose the .format() style. Because then the tool will not complain about anything.

I see quite a number of

    ('some long string'
    '')   # <- This looks like a tool bug to me

instances and I think ruff should be fixed about that.

@lucascolley
Copy link
Member Author

lucascolley commented Nov 14, 2023

This looks like a tool bug to me

IIUC this is because the linter is intended to be used in tandem with a formatter (i.e. linter is minimal in formatting changes). This is difficult for SciPy to adopt short of formatting the entire codebase (far too disruptive).

Edit: I'm happy to do a full pass through the diff to fix these. I'm quite busy right now so it will take a little while.

@melissawm
Copy link
Contributor

Docs build failure is fixed in main, not related to this PR.

@lucascolley lucascolley added needs-work Items that are pending response from the author needs-decision Items that need further discussion before they are merged or closed labels Nov 15, 2023
Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

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

I skimmed this, mostly trusting that the automated linting didn't make any logical errors. I noted a few of the ugly things I found toward the top, but they are quite common, so I didn't continue, since we are supposed to rush this. Feel free to ignore these suggestions because they're not nearly complete.

The one thing I'll ask is why the lint check is passing, because some of these lines are far longer than the limit. Is that check not enabled here?

I thought this was related to the line length stuff, but I guess not. We will need a separate pass for that, I suppose.

scipy/_build_utils/system_info.py Outdated Show resolved Hide resolved
scipy/_lib/decorator.py Outdated Show resolved Hide resolved
scipy/constants/_codata.py Show resolved Hide resolved
scipy/fft/_pocketfft/basic.py Outdated Show resolved Hide resolved
scipy/interpolate/_fitpack_impl.py Outdated Show resolved Hide resolved
scipy/ndimage/_measurements.py Outdated Show resolved Hide resolved
scipy/odr/_odrpack.py Outdated Show resolved Hide resolved
scipy/odr/_odrpack.py Show resolved Hide resolved
scipy/optimize/_shgo_lib/_complex.py Outdated Show resolved Hide resolved
scipy/stats/tests/test_distributions.py Outdated Show resolved Hide resolved
@lucascolley
Copy link
Member Author

Thanks Matt, I added the needs-work label since I intend to do one full pass for style myself.

@lucascolley
Copy link
Member Author

lucascolley commented Nov 16, 2023

astral-sh/ruff#8683 at least some of the formatting issues will be fixed in the next ruff release. I might wait for that and remake the PR (as long as a force push wouldn't be too disruptive?)

I'm also inclined to wait for gh-19529 in case anything else arises from there.

@mdhaber mdhaber marked this pull request as draft November 16, 2023 14:02
@stefanv
Copy link
Member

stefanv commented Nov 16, 2023

@lucascolley In the interest of time, consider using ruff from their main branch?

@lucascolley
Copy link
Member Author

down to 22 errors which need to be fixed manually. There may be more once I rebase for gh-19529.

@lucascolley lucascolley removed the needs-work Items that are pending response from the author label Nov 16, 2023
@lucascolley
Copy link
Member Author

A slight change is needed for mypy from CI but I'lll wait until I've rebased on gh-19529 and fixed any additional errors. After that, I'll do a pass for style and check if any of the old comments still apply, then mark as ready for review. If everything looks good then, we may want to condense down to two commits for the purpose of the blame-ignore.

@lucascolley
Copy link
Member Author

@j-bowhay @stefanv would either of you like to give this a look? No rush at all but I think it's ready. The safe auto fixes should be fine so perhaps just check the unsafe ones and my manual fixes?

Copy link
Member

@j-bowhay j-bowhay left a comment

Choose a reason for hiding this comment

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

Changes seem reasonable but might be useful for another pair of eyes as it is easy to miss stuff

Comment on lines 1148 to +1149
raise ValueError("f(a) and f(b) must have different signs, but "
"f({:e})={:e}, f({:e})={:e} ".format(a, fa, b, fb))
f"f({a:e})={fa:e}, f({b:e})={fb:e} ")
Copy link
Member

Choose a reason for hiding this comment

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

Is the alignment here correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah no, good spot 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

On second thought I think this is correct.

@stefanv
Copy link
Member

stefanv commented Nov 21, 2023

OK, let's get this in before it goes stale. Do you want to make the .git-blame-ignore-revs commit(s)?

@lucascolley
Copy link
Member Author

OK, let's get this in before it goes stale. Do you want to make the .git-blame-ignore-revs commit(s)?

👍 I'll address Jake's comment, squash down to 1 clean-up commit and add it to the ignored revisions (tomorrow). Thanks all for the quick review!

@lucascolley lucascolley removed the needs-decision Items that need further discussion before they are merged or closed label Nov 21, 2023
@lucascolley
Copy link
Member Author

@stefanv good to go once CI is okay?

@stefanv
Copy link
Member

stefanv commented Nov 21, 2023

I see the same failure on PRs recently merged to main, so let's get this in before it becomes impossible to merge.

@stefanv stefanv merged commit 731b325 into scipy:main Nov 21, 2023
19 of 22 checks passed
@stefanv
Copy link
Member

stefanv commented Nov 21, 2023

Thanks very much @lucascolley.

@lucascolley
Copy link
Member Author

lucascolley commented Nov 21, 2023

thanks all!

I imagine there isn't appetite for any more big changes soon, but if there are any other rules which you think may be worth our time @stefanv, let me know and I'm happy to look into them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants