Skip to content

CLN: cleanup unused bits now that Python 3.9 was dropped#16183

Merged
mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:mnt/cleanup_post_3.10_adoption
Mar 11, 2024
Merged

CLN: cleanup unused bits now that Python 3.9 was dropped#16183
mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:mnt/cleanup_post_3.10_adoption

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

A quick follow up to #15603

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

Comment thread astropy/io/fits/tests/test_image.py
@neutrinoceros neutrinoceros force-pushed the mnt/cleanup_post_3.10_adoption branch from 3fd2465 to 06fda69 Compare March 11, 2024 14:47
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.

Great, but see in-line for units.structured

Comment thread astropy/units/structured.py Outdated
"""

from __future__ import annotations # For python < 3.10
from __future__ import annotations
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.

If this was for python < 3.10, can we not just remove this import?

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 wasn't sure at first, since this import has been propagating in the code base for seemingly different reasons since this comment was written, but upon checking I think you're right. Thanks !

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.

For here probably fine, but let me ping @nstarman to ask if we still need from __future__ import annotations in general now that our minimum python is 3.10.

@neutrinoceros neutrinoceros force-pushed the mnt/cleanup_post_3.10_adoption branch from 06fda69 to 45ae379 Compare March 11, 2024 15:10
@pllim pllim added this to the v6.1.0 milestone Mar 11, 2024
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.

This now looks all OK to me, so I'll approve, but will wait with merging to give @nstarman time to pipe in.

Comment thread astropy/modeling/fitting.py Outdated
populate_entry_points(ep.select(group="astropy.modeling"))


_populate_ep()
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.

Can't we just remove the private function entirely?

Suggested change
_populate_ep()
populate_entry_points(entry_points().select(group="astropy.modeling"))

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.

done


# The test below raised a `ResourceWarning: unclosed transport` exception
# due to a bug in Python <=3.10 (cf. cpython#90476)
# due to a bug in PYTHON_LT_3_11 (cf. cpython#90476)
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.

The intention behind having these PYTHON_LT_* variables was that when we drop support for some Python version then we can simply delete the definition of the corresponding variable causing all the code that is using it to raise an error, and this would prevent compatibility code from staying around longer than it is needed. But this setup also means that strings like that should never be grepped for, so I'm not convinced this change is helpful.

I also think we should stop using this PYTHON_LT_* variables because we are now using Ruff and its rule UP036 can recognize comparisons involving sys.version_info calls and update the code automatically (possibly requiring the --unsafe-fixes option).

The best thing to do here would be to replace the comment with code that explicitly uses sys.version_info.

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.

For the numpy equivalent, I tend to do the find astropy -name \*.py -exec grep NUMPY_LT... - but if it is easy to refactor with a version check, that would indeed be ideal.

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.

Amusingly, I wrote UP036 in the original (pyupgrade) code, so I'm well aware it exists 😅
However my goal here is absolutely not to revolutionise how astropy code is written, and I believe it would be best left out of this PR ?

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.

@mhvk wrote

For the numpy equivalent, I tend to do the find astropy -name \*.py -exec grep NUMPY_LT...

git grep NUMPY_LT_... is shorter, produces more useful output (unless you add something to that find incantation of yours that you didn't write down) and faster even if you don't specify you are only interested in .py files in astropy/ (although you could with git grep NUMPY_LT_... -- 'astropy/*.py').

@neutrinoceros wrote

However my goal here is absolutely not to revolutionise how astropy code is written, and I believe it would be best left out of this PR ?

The title of your pull request says that it is removing Python 3.9 compatibility code, so this particular change would be out of scope here. But overall it would be good to write (or rewrite) any compatibility code in a way that prevents it from outliving its usefulness.

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.

Thanks, learn something new every day!

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.

Initially I misread the comment and thought it was not relevant in 3.10. Happy to just leave it out of this PR.

But overall it would be good to write (or rewrite) any compatibility code in a way that prevents it from outliving its usefulness.

for the record I agree (this is what I wrote UP036 for), but I think I recall there was some objections when I proposed this refactor in astropy some time ago (but I can't remember the exact context).

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 dropped the change)

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.

FWIW, what I remember about auto-upgrade is mostly that some of us (including me) felt that one should not upgrade code just for the sake of it (i.e., one doesn't have to use |= to update a dict, using .update() is fine).

Automatically recognizing pieces of code that are no longer useful does not fall in that category, though!

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'll open another PR to propose this.

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.

for posterity: this is #16186

This module defines structured units and quantities.
"""

from __future__ import annotations # For python < 3.10
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.

If from __future__ import annotations was only needed to enable writing down union types using the |-operator then the import can be safely removed now. However, in files that have an if TYPE_CHECKING: block removing these lines would require rewriting (possibly many) annotations as string literals, which doesn't sound helpful. Luckily it is simple to find out if this import is needed or not: if it is then removing it causes the code to fail already at import time.

@neutrinoceros neutrinoceros force-pushed the mnt/cleanup_post_3.10_adoption branch from 45ae379 to 540ab48 Compare March 11, 2024 18:16
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.

Great, thanks for the further simplifications. Let's get this in!

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.

4 participants