-
-
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
Support running with -OO #15789
base: main
Are you sure you want to change the base?
Support running with -OO #15789
Conversation
- Adds @skipif_no_docstrings and DOCSTRINGS_DISABLED to astropy/conftest.py
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.
|
👋 Thank you for your draft pull request! Do you know that you can use |
Coverage is failing because of assert replaces- will try to add test cases for the new errors. I've chosen to replace asserts with descriptive errors ( |
Re: #15789 (comment) @nstarman , do you know since you ported the config to pyproject.toml a while ago? |
It was failing earlier when I made that comment but it looks like it's passing now (though there's still an annotation that doesn't look right). Should this get a single changelog entry at the top level or multiple for each submodule? |
Since for the user of regular python, there is no behaviour change, I think it should be a top-level feature one that |
Are any of these |
No, they aren't in hot paths generally. And, yes, of course good for people who run with |
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.
Thanks for the PR! I only looked at the cosmology changes, which all look good.
My more general comment is to put "TODO:" markers in your comments about replacing AssertionErrors.
codecov failures look spurious to me- and they seem to change randomly despite no changes to the code. |
Yes, I've sadly learned to just ignore code coverage entirely... |
The patch coverage is pretty good. It's the project coverage that's problematic. |
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 have a few remarks regarding the changes to pyproject.toml
.
pyproject.toml
Outdated
] | ||
"**/tests/*.py" = [ | ||
"S101", # Use of assert detected | ||
] | ||
"astropy/nddata/_testing.py" = [ | ||
"S101", # Use of assert detected | ||
] | ||
".pyinstaller/*.py" = ["INP001"] # Not a package. | ||
"conftest.py" = ["INP001"] # Part of configuration, not a package. | ||
"docs/*.py" = [ | ||
"INP001", # implicit-namespace-package. The examples are not a package. | ||
"S101", # Use of assert detected |
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.
It is not obvious to me that we should permanently ignore S101
in all of docs/
just because of two files in docs/wcs/examples/
.
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.
Cosmology & Units: LGTM. Thanks @alchzh.
…o file-scoped comment
"S101", # Use of assert detected | ||
] | ||
".pyinstaller/*.py" = ["INP001"] # Not a package. | ||
"conftest.py" = ["INP001"] # Part of configuration, not a package. | ||
"docs/*.py" = [ | ||
"INP001", # implicit-namespace-package. The examples are not a package. | ||
"S101", # Use of assert detected |
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.
Here's what the violations in docs/
look like (in current main
):
$ ruff check --select S101 --show-source docs/
docs/wcs/examples/from_file.py:46:5: S101 Use of `assert` detected
|
44 | # These should be the same as the original pixel coordinates, modulo
45 | # some floating-point error.
46 | assert np.max(np.abs(pixcrd - pixcrd2)) < 1e-6
| ^^^^^^ S101
47 |
48 | # The example below illustrates the use of "origin" to convert between
|
docs/wcs/examples/from_file.py:54:5: S101 Use of `assert` detected
|
52 | y = 0
53 | origin = 0
54 | assert (w.wcs_pix2world(x, y, origin) ==
| ^^^^^^ S101
55 | w.wcs_pix2world(x + 1, y + 1, origin + 1))
|
docs/wcs/examples/programmatic.py:41:1: S101 Use of `assert` detected
|
39 | # These should be the same as the original pixel coordinates, modulo
40 | # some floating-point error.
41 | assert np.max(np.abs(pixcrd - pixcrd2)) < 1e-6
| ^^^^^^ S101
42 |
43 | # The example below illustrates the use of "origin" to convert between
|
docs/wcs/examples/programmatic.py:49:1: S101 Use of `assert` detected
|
47 | y = 0
48 | origin = 0
49 | assert (w.wcs_pix2world(x, y, origin) ==
| ^^^^^^ S101
50 | w.wcs_pix2world(x + 1, y + 1, origin + 1))
|
Found 4 errors.
We might want to replace these assert
statements with np.testing.assert_allclose()
and np.testing.assert_array_equal()
instead of ignoring S101 in docs/
.
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.
That's an option, though I must admit I don't quite like how the checkers here are affecting good & clear code. I somewhat prefer to leave the warts with the checker set-up files rather than with the code, i.e., either just exclude docs -- where presumably the author, like here, made a conscious choice to use assert
-- or just exclude these two files.
p.s. This PR is to support running python with -OO
- for that purpose, none of this should really matter...
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.
As far as I can tell docs/wcs/examples/from_file.py
exists only so that docs/wcs/loading_from_fits.rst
can include it. But the latter contains only 8 lines in total. Perhaps it would be best to move the contents of from_file.py
to loading_from_fits.rst
. Likewise for docs/wcs/examples/programmatic.py
and docs/wcs/example_create_imaging.rst
.
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.
For now, I will move the exclude tule for docs to ruff.toml
(just to make the CI happy) and maybe a separate PR can be made if the example files need to be modified or moved.
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.
That's reasonable.
Description
This pull request supports the
-OO
/PYTHONOPTIMIZE=2
options byassert
outside of tests (and enabling the corresponding ruff rule)foo.__doc__ is not None
checks around docstring code-OO
(skipping docstring/help() tests)Fixes #15052