Repository navigation
BUG: ensure that docstrings for read/write public methods are always available for inspection (nddata) - #17555
neutrinoceros wants to merge 1 commit into
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.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
nddata)
|
The errors here are puzzling. I'll come back to this later today if I have time. |
b060742 to
a35d908
Compare
|
Actually the problem was quite trivial, I'm just paying the price of context switching. |
| reader_doc += os.linesep | ||
| if doc is not None: | ||
| reader_doc += inspect.cleandoc(doc) | ||
|
|
|
|
||
| # this docstring *must* be available at runtime to support `UnifiedReadWrite.help` | ||
| # so we attach it manually, which is robust against PYTHONOPTIMIZE=2 | ||
| fits_ccddata_reader.__doc__ = """ |
There was a problem hiding this comment.
A quick google search didn't reveal anything about being able to make a decorator that prevents the docstring from being removed. However if the optimizer is just doing static AST parsing then perhaps a simple decorator would work.
@keep_doc("""docstring""")
def function()
Worth a try? Keeps the docs and function more closely associated.
There was a problem hiding this comment.
I don't have a strong opinion, but it's certainly feasible. I'll push an implementation of this in a minute, let me know what you think !
There was a problem hiding this comment.
Does this works with the optimizer flag?
There was a problem hiding this comment.
It does. I should have said that when I pushed, but I did test it.
…available for inspection (nddata)
a35d908 to
1bfced5
Compare
|
tl;dr -- Didn't we decide in another PR that docstring missing in optimized mode is okay? So why this special treatment here? |
|
The help function requires the docstring. We could either: have a broken function, refactor the help function to be a no-op in optimized mode, or keep the docstring. |
That would be simpler, right, and localize this optimized mode stuff in one file instead of spread it out over different subpackages that hook into the unified I/O? |
|
I suppose the Q though is: when do people use python's optimized mode? If it's only to do production runs, then making |
|
In Python the natural way of documenting things is using docstrings. The fact that a few Independently from the previous point, if a user has explicitly told Python to remove the docstrings then any clever tricks that insert the docstrings anyways clearly go against the user's wishes. |
|
Yes, making |
|
👍 to not sneakily trying to keep docstrings, and instead adjusting |
|
Someone using PYTHONOPTIMIZE=2 should not expect things like |
|
Yes, in hindsight this seems like the correct approach. I just didn't know how much tinkering I'd need before I gave it a try, but I agree that it's too much. Let's just close this, as well as #17557 and revert #17548. |
|
Thanks, @neutrinoceros -- Sometimes one needs to see the code to realize it is the wrong approach! |
Description
ref #17472