-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add missing dunder __all__ to star-imported modules #15781
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.
|
Hmm, @nstarman or @eerovaher , did you set up the ruff check for this stuff? I vaguely remember a bunch of discussions about star imports. So either this is unnecessary or those checks are not working? @alchzh , if this PR were to move forward, I think it needs 2 change logs because it touches two completely unrelated subpackages. Or better yet, 2 different PRs. But let's wait to hear back first. Thanks! |
I don't think Ruff supports checking if |
Ruff has a rule about using |
As suggested in APE 22 we can make a pre-commit hook that checks for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've split the changelog into two fragments in this PR. |
Thanks! I think the diff technically looks good now but we have to wait for Happy holidays! |
Sounds great. I hope that all devs are enjoying the holidays more than bored student with nothing to do after the semester ends 🤣 Happy Holidays! |
@@ -40,6 +40,8 @@ | |||
DITHER_SEED_CLOCK, | |||
) | |||
|
|||
__all__ = ["COMPRESSION_ENABLED", "CompImageHDU"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PEP8 __all__
should be placed after the module docstring, but before the imports, also in the other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except
For __future__
imports, which precede everything but the module docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow the convention in the rest of the library: 232 files define __all__
after the imports (excluding from __future__ ...
while only 22 define __all__
before imports by my count. This is one of the PEP8 suggestions that no one know about or bother to follow if they do:
- none of the style checkers/formatters (pycodestyle, black, ruff, isort, etc.) support it, not even with extensions
numpy
,scipy
,pandas
, and probably many more scientific libraries put__all__
after imports
So I figured in this case it's better to be consistent than follow an unenforced guideline. But I'll defer to you all if you feel strongly about sticking to PEP8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of astropy
places __all__
below the imports and changing that is not a high priority, but I don't see a good reason why brand new __all__
definitions should knowingly violate PEP8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should open an issue on Ruff's isort to enable sorting __all__
to be above the imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.
All other files in io
and visualizations
and 94% of all astropy files (with __all__
) place __all__
after imports, so unless there's a explicit directive to change the style in all new code I think doing it just for this PR violates both consistency within one module and consistency within a project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eerovaher I suggest that since this discussion affects Astropy package-wide we should have it post getting this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this in. We should come up with our __all__
location policy in a followup PR or something.
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
@pllim can we merge this or does it need a rebase? |
seeing the amount of now-required jobs that never ran here I would recommend a rebase |
I can't trigger a re-base nor a re-run. We should add manual running to the tests CI for the latter. |
Hmm, not sure what you mean here, you should be able to rebase and force push to author's branch here as a core maintainer. |
You can already do this. But if you don't want to, please let me know and I can do it for you. Thanks. Probably not the coolest way but it works.
|
77036c0
to
eb122bb
Compare
Would you mind rebasing again to make sure RTD builds? If not, I can do it. Please let me know. Thanks for your patience! |
not sure why pre-commit didn't catch this before...
eb122bb
to
e3f3980
Compare
Thanks, all! |
Description
This pull request is to address a couple of modules (
astropy.io.fits.hdu.compressed
andastropy.visualization
) that currently have unintended exports because of star-imported modules without__all__
defined.Removes the following exports from
astropy.visualization
:{'np'}
Removes the following exports from
astropy.io.fits.hdu.compressed
:{'lazyproperty', 'compress_image_data', 'ctypes', 'DTYPE2BITPIX', 'math', 'BinTableHDU', 'DELAYED', 'BITPIX2DTYPE', 'deprecated_renamed_argument', 'np', 'time', 'FITS_rec', 'ExtensionHDU', 'conf', 'simplify_basic_index', 'suppress', 'decompress_image_data_section', 'ImageHDU'}
Represents a breaking change, though I hope no one is accessing NumPy as
astropy.visualization.np
or ctypes asastropy.io.fits.hdu.compressed.ctypes
. Apart from external modules or names exported correctly at a different location, this makescompress_image_data
anddecompress_image_data_section
"private". I don't think they're supposed to be accessible onastropy.io.fits.hdu.compressed
since they're defined in_tiled_compression.py
, but pinging @astrofrog to check.