This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inconsistent docstrings in struct module
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: SilentGhost, belopolsky, georg.brandl, mark.dickinson
Priority: normal Keywords: patch

Created on 2010-06-11 15:32 by belopolsky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue8973.patch mark.dickinson, 2010-06-12 14:39
issue8973-Struct.diff belopolsky, 2010-06-12 19:25 Expanded Struct.__doc__
struct.py.diff SilentGhost, 2011-01-31 11:50
Messages (19)
msg107556 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-11 15:32
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.
msg107557 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-11 15:41
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)/.

2.  For some reason struct.Struct does not show up in help(struct).
msg107558 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-11 15:42
Thanks for the reports;  I'll look at this a little later.
msg107655 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 14:34
Here's a patch.  Alexander, do you want to check it for sanity?
msg107656 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 14:34
N.B. The patch doesn't fix the missing struct.Struct documentation issue;  I'll look at that separately.
msg107657 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 14:45
The docstrings need to be rewrapped to 72 characters;  I'll do this once the wording is settled.
msg107658 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-12 15:18
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__(...)
 |      x.__init__(...) initializes x; see x.__class__.__doc__ for signature

I think this is inherited, but quite confusing here because help(Struct) does not have signature.   Maybe just add signature to help(Struct).
msg107659 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 15:22
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.)
msg107660 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 15:22
I also accidentally included the docstring changes in r81947;  those were reverted in r81948.
msg107663 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 15:44
Committed patch (with additional changes suggested by Alexander) in r81949.  Only the __init__ doc issue remains.
msg107664 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-12 15:51
See issue #8983 for the the __init__ doc discussion since it is not specific to the struct module.
msg107666 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 15:53
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?
msg107686 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-12 19:25
How does issue8973-Struct.diff look?
msg107687 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 19:30
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.
msg107688 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-12 19:38
Committed in r81961.   Yes, I used "format" for consistency with the manual, but on the second thought consistency within help() is more important.
msg127593 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-01-31 11:50
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?
msg127606 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-01-31 15:48
The proposed patch looks fine to me, but it is attached to the wrong issue.  It belongs to #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.
msg127609 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-01-31 15:56
Wait, #8973 *is* this issue.  But r81947 is clearly not only about docstrings.  We definitely need a separate issue.  This is too confusing.
msg127626 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-01-31 17:23
new issue #11081 was created for struct.__all__ fix
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53219
2011-01-31 17:23:54SilentGhostsetstatus: open -> closed
nosy: georg.brandl, mark.dickinson, belopolsky, SilentGhost
messages: + msg127626
2011-01-31 15:56:04belopolskysetnosy: georg.brandl, mark.dickinson, belopolsky, SilentGhost
messages: + msg127609
2011-01-31 15:55:42belopolskysetnosy: georg.brandl, mark.dickinson, belopolsky, SilentGhost
messages: - msg127607
2011-01-31 15:51:14belopolskysetnosy: georg.brandl, mark.dickinson, belopolsky, SilentGhost
messages: + msg127607
2011-01-31 15:48:46belopolskysetnosy: georg.brandl, mark.dickinson, belopolsky, SilentGhost
messages: + msg127606
2011-01-31 11:50:15SilentGhostsetstatus: closed -> open
files: + struct.py.diff

nosy: + georg.brandl, SilentGhost
messages: + msg127593
2010-06-12 19:42:03belopolskysetstatus: open -> closed
resolution: accepted
stage: resolved
2010-06-12 19:38:10belopolskysetmessages: + msg107688
2010-06-12 19:30:25mark.dickinsonsetmessages: + msg107687
2010-06-12 19:25:01belopolskysetfiles: + issue8973-Struct.diff

messages: + msg107686
2010-06-12 15:53:50mark.dickinsonsetassignee: mark.dickinson -> belopolsky
messages: + msg107666
2010-06-12 15:51:21belopolskysetmessages: + msg107664
2010-06-12 15:44:21mark.dickinsonsetmessages: + msg107663
2010-06-12 15:22:48mark.dickinsonsetmessages: + msg107660
2010-06-12 15:22:16mark.dickinsonsetmessages: + msg107659
2010-06-12 15:18:03belopolskysetmessages: + msg107658
2010-06-12 14:45:10mark.dickinsonsetmessages: + msg107657
2010-06-12 14:39:20mark.dickinsonsetfiles: - issue8973.patch
2010-06-12 14:39:15mark.dickinsonsetfiles: + issue8973.patch
2010-06-12 14:34:30mark.dickinsonsetmessages: + msg107656
2010-06-12 14:34:01mark.dickinsonsetfiles: + issue8973.patch
keywords: + patch
messages: + msg107655
2010-06-11 15:42:54mark.dickinsonsetassignee: mark.dickinson
messages: + msg107558
2010-06-11 15:41:38belopolskysetmessages: + msg107557
2010-06-11 15:32:36belopolskycreate