Skip to content

RFC: inline usage of sys.version_info to enable automated clean up of compatibility code#16186

Merged
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:rfc/auto_upgradable_compat_code
Mar 12, 2024
Merged

RFC: inline usage of sys.version_info to enable automated clean up of compatibility code#16186
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:rfc/auto_upgradable_compat_code

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

Description

Following the discussion in #16183 (comment)
This one is on the house (I'm not going to bill it), I'm just mostly scratching my own itch

The goal is to make future PRs similar to #15063 a tad easier to write and maintain by enabling automatic cleanups for compatibility branches using the UP036 rule from pyupgrade (and re-implemented in ruff).

I also note that there's actually an existing precedent for using sys.version_info instead of PYTHON_LT_* internally, so this actually uniformizes the code base.

I believe @eerovaher @mhvk and @nstarman would be interested in this.

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

@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions
Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@neutrinoceros neutrinoceros force-pushed the rfc/auto_upgradable_compat_code branch from df1e6dc to 21b377a Compare March 11, 2024 19:25
@neutrinoceros neutrinoceros force-pushed the rfc/auto_upgradable_compat_code branch from 21b377a to d286c11 Compare March 11, 2024 19:30
if PYTHON_LT_3_11
else f"property 'name' of {cosmo.__class__.__name__!r} object has no setter"
)
if sys.version_info < (3, 11):
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.

note to reviewers: the reason I also refactored the ternary out is that, to the best of my knowledge, UP036 auto cleanup only works for if/else patterns. That is, unless the ruff reimplementation was made smarter than my original code.

@neutrinoceros neutrinoceros force-pushed the rfc/auto_upgradable_compat_code branch from d286c11 to 92b843c Compare March 11, 2024 19:34
Comment thread astropy/utils/compat/misc.py
@pllim pllim added this to the v6.1.0 milestone Mar 11, 2024
else:
mark = lambda f: f

@mark
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.

Instead of introducing no-op marker, maybe cleaner to use warnings.filterwarnings context manager inside this function?

Copy link
Copy Markdown
Contributor Author

@neutrinoceros neutrinoceros Mar 11, 2024

Choose a reason for hiding this comment

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

It would, only I don't know which part of this long test is supposed to trigger that warning (and I can't seem to reproduce it locally), so it seemed to me that a no-op decorator would at least keep the diff minimal.

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.

I was gonna suggest the whole test go inside the context manager but yeah, would be larger diff. Leave it as is then. Thanks!

Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

I quite like getting rid of the PYTHON_LT_* stuff. Thanks!

@neutrinoceros neutrinoceros marked this pull request as ready for review March 11, 2024 21:18
@neutrinoceros neutrinoceros requested review from a team, saimn and taldcroft as code owners March 11, 2024 21:18
@neutrinoceros neutrinoceros requested a review from nstarman March 11, 2024 21:18
Copy link
Copy Markdown
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.

Everything LGTM! Very nice to not have to remember to upgrade this code in the future.

@pllim pllim merged commit c813aca into astropy:main Mar 12, 2024
@pllim
Copy link
Copy Markdown
Member

pllim commented Mar 12, 2024

Thanks, all!

@neutrinoceros neutrinoceros deleted the rfc/auto_upgradable_compat_code branch March 12, 2024 13:44
@neutrinoceros neutrinoceros mentioned this pull request Mar 13, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants