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
Inconsistent docstrings in struct module #53219
Comments
Module level pack, unpack etc. methods have similar functionality with Struct instance methods, but docs are different. The immediate issue is the lack of signature in the module level methods' docstrings. $ ./python.exe -m pydoc struct.Struct.pack
Help on method_descriptor in struct.Struct: struct.Struct.pack = pack(...)
S.pack(v1, v2, ...) -> bytes
Return a bytes containing values v1, v2, ... packed according to this
Struct's format. See struct.__doc__ for more on format strings. and $ ./python.exe -m pydoc struct.pack
Help on built-in function pack in struct: struct.pack = pack(...)
Return bytes containing values v1, v2, ... packed according to fmt. |
Two more bits: 1. "See struct.__doc__", while technically correct, is not user friendly. If you copy struct.__doc__ to >>> prompt, you get an ugly repr of a multiline string. I suggest s/struct.__doc__/help(struct)/.
|
Thanks for the reports; I'll look at this a little later. |
Here's a patch. Alexander, do you want to check it for sanity? |
N.B. The patch doesn't fix the missing struct.Struct documentation issue; I'll look at that separately. |
The docstrings need to be rewrapped to 72 characters; I'll do this once the wording is settled. |
calcsize() still does not have signature in docstring. A nit: maybe follow calcsize() lead and say "format string fmt" rather than just "fmt". One more __doc__ mention: in Struct docstring, | __init__(...) I think this is inherited, but quite confusing here because help(Struct) does not have signature. Maybe just add signature to help(Struct). |
r81947 fixes the missing struct.Struct entry in struct.help. (pydoc was relying on the inspect module to correctly guess the module for struct.Struct, and inspect was getting it wrong. Adding __all__ to the struct module saves inspect from having to guess.) |
I also accidentally included the docstring changes in r81947; those were reverted in r81948. |
Committed patch (with additional changes suggested by Alexander) in r81949. Only the __init__ doc issue remains. |
See issue bpo-8983 for the the __init__ doc discussion since it is not specific to the struct module. |
Apart from the pydoc __init__ issue, the Struct class documentation should probably be expanded a bit. At the moment, it's just: PyDoc_STRVAR(s__doc__, "Compiled struct object"); Alexander, interested in producing a patch? |
How does bpo-8973-Struct.diff look? |
Looks fine. I'd probably call the argument 'fmt' rather than 'format', for consistency. Please commit, with or without the 'format' -> 'fmt' change, as you choose. |
Committed in r81961. Yes, I used "format" for consistency with the manual, but on the second thought consistency within help() is more important. |
r81947 introduced this issue: >>> from struct import *
>>> pack_into
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
pack_into
NameError: name 'pack_into' is not defined struct.__all__ has a duplicate entry and misses pack_into. Patch is attached, test passes. Seems quite innocent to me, could it make into 3.2, George? |
The proposed patch looks fine to me, but it is attached to the wrong issue. It belongs to bpo-8973 or better yet to follow RC2 rules pedantically, it should be posted in a separate issue. This is important, because this issue is limited to docstrings and may be considered documentation only, but the proposed parch affects behavior. Still I would be +1 on applying it. |
Wait, bpo-8973 *is* this issue. But r81947 is clearly not only about docstrings. We definitely need a separate issue. This is too confusing. |
new issue bpo-11081 was created for struct.__all__ fix |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: