CLN: cleanup unused bits now that Python 3.9 was dropped#16183
Conversation
|
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.
|
3fd2465 to
06fda69
Compare
mhvk
left a comment
There was a problem hiding this comment.
Great, but see in-line for units.structured
| """ | ||
|
|
||
| from __future__ import annotations # For python < 3.10 | ||
| from __future__ import annotations |
There was a problem hiding this comment.
If this was for python < 3.10, can we not just remove this import?
There was a problem hiding this comment.
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 !
There was a problem hiding this comment.
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.
06fda69 to
45ae379
Compare
| populate_entry_points(ep.select(group="astropy.modeling")) | ||
|
|
||
|
|
||
| _populate_ep() |
There was a problem hiding this comment.
Can't we just remove the private function entirely?
| _populate_ep() | |
| populate_entry_points(entry_points().select(group="astropy.modeling")) |
|
|
||
| # 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Thanks, learn something new every day!
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
(I dropped the change)
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
I'll open another PR to propose this.
| This module defines structured units and quantities. | ||
| """ | ||
|
|
||
| from __future__ import annotations # For python < 3.10 |
There was a problem hiding this comment.
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.
45ae379 to
540ab48
Compare
mhvk
left a comment
There was a problem hiding this comment.
Great, thanks for the further simplifications. Let's get this in!
A quick follow up to #15603