Skip to content

Apply monthly pre-commit update manually#17843

Merged
pllim merged 1 commit intoastropy:mainfrom
eerovaher:manual-pre-commit-update
Mar 4, 2025
Merged

Apply monthly pre-commit update manually#17843
pllim merged 1 commit intoastropy:mainfrom
eerovaher:manual-pre-commit-update

Conversation

@eerovaher
Copy link
Member

@eerovaher eerovaher commented Mar 3, 2025

Description

The manual updates allow implementing better fixes to Ruff rule FURB188 (slice-to-remove-prefix-or-suffix) in two files in io.*. Note that #17619 and #17620 were opened almost two months ago with the purpose of making the patches the pre-commit autoupdates would apply smaller, but they still haven't been merged. Given that pre-commit has already tried to apply its monthly updates twice since their opening, they are no longer valuable as separate pull requests.

Closes #17615, closes #17619, closes #17620, closes #17841

  • 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.

edit by @neutrinoceros: use the correct path for where files with FURB188 are.

The manual updates allow implementing better fixes to Ruff rule FURB188
(slice-to-remove-prefix-or-suffix) in two files in `io/fits`.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

tform = compressed_coldefs[column_name].format
if tform.startswith("1"):
tform = tform[1:]
tform = compressed_coldefs[column_name].format.removeprefix("1")
Copy link
Member Author

Choose a reason for hiding this comment

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

The automatic Ruff update would have been

      tform = compressed_coldefs[column_name].format
-     if tform.startswith("1"):
-         tform = tform[1:]
+     tform = tform.removeprefix("1")

keyword = keyword.strip().upper()
if keyword.startswith("HIERARCH "):
keyword = keyword[9:]
keyword = keyword.strip().upper().removeprefix("HIERARCH ")
Copy link
Member Author

Choose a reason for hiding this comment

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

The automatic Ruff update would have been

          keyword = keyword.strip().upper()
-         if keyword.startswith("HIERARCH "):
-             keyword = keyword[9:]
+         keyword = keyword.removeprefix("HIERARCH ")

Copy link
Member

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

🚀

@neutrinoceros
Copy link
Contributor

Thanks. I see the diff count is slightly different here than on #17841, can you explain where are the two additional lines you removed ?
Otherwise, LGTM. I hope we can strip the bandaid this time and I'd like to merge this within the week if no one objects.

Copy link
Contributor

@dhomeier dhomeier left a comment

Choose a reason for hiding this comment

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

Thanks, io.ascii (and from a quick glimpse, the rest of io) looking good!

lim_vals = (
f"[{floor(col.min * 100) / 100.}/{ceil(col.max * 100) / 100.}]"
)
lim_vals = f"[{floor(col.min * 100) / 100.0}/{ceil(col.max * 100) / 100.0}]"
Copy link
Contributor

Choose a reason for hiding this comment

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

As long as I don't need to understand why Ruff is now undoing formatting that was introduced by Black rules in the first place, definitely +1 on this!

Copy link
Contributor

Choose a reason for hiding this comment

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

black's format isn't immutable either: it's updated once a year. Ruff follows a similar schedule and both seems to be introducing identical or very similar changes so far.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it's also changing the default line length again between versions?
Personally I'm all in favour of the longer limits, and the fewer = ($ constructs, the better, but I thought we had discussed at some length (pun inevitable) that the then-black-default of 88 was preferable to most.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the default is still 88. Ruff is just getting intentionally looser on this specific rule. I don't know which specific rule change causes this, but I think it makes perfect sense to forfeit formatting on such a line: there is no safe way to split an arbitrary string, and putting parens doesn't guarantee that the limit will be respected in the general case any way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, just what I had been looking for, but searching through the entire changelog did not bring up anything related. Though I still don't understand how that rule applies here, since it the f-string part of that expression had never been split in the first place, but I guess I don't have to.

@eerovaher
Copy link
Member Author

@neutrinoceros asked

Thanks. I see the diff count is slightly different here than on #17841, can you explain where are the two additional lines you removed ?

#17843 (comment)

#17843 (comment)

@pllim pllim merged commit e0493a2 into astropy:main Mar 4, 2025
33 checks passed
@pllim
Copy link
Member

pllim commented Mar 4, 2025

Thanks, all!

@eerovaher eerovaher deleted the manual-pre-commit-update branch March 5, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MNT: upgrading to ruff 0.9

5 participants