classification
Title: pydoc doesn't find all module doc strings
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ping Nosy List: ajaksu2, brianvanden, eric.araujo, kjohnson, ping
Priority: normal Keywords: easy

Created on 2005-04-18 12:18 by kjohnson, last changed 2010-08-21 13:50 by BreamoreBoy.

Files
File name Uploaded Description Edit
pydoc_fix.diff kjohnson, 2005-04-18 20:04 Revised patch recognizes any triple-quoted string
Messages (6)
msg25049 - (view) Author: Kent Johnson (kjohnson) * Date: 2005-04-18 12:18
pydoc.synopsis() attempts to find a module's doc string
by parsing the module text. But the parser only
recognizes strings created with """ and r""". Any other
docstring is ignored.

I've attached a patch against Python 2.4.1 that fixes
pydoc to recognize ''' and r''' strings but really it
should recognize any allowable string format.
msg25050 - (view) Author: Ka-Ping Yee (ping) * (Python committer) Date: 2005-04-18 18:23
Logged In: YES 
user_id=45338

PEP 257 recommends: "For consistency, always use """triple
double quotes""" around docstrings."  I think that's why
this was originally written to only look for triple
double-quotes.

Are there a large number of modules written using
triple-single quotes for the module docstring?
msg25051 - (view) Author: Kent Johnson (kjohnson) * Date: 2005-04-18 20:04
Logged In: YES 
user_id=49695

I don't know if there are a large number of modules with
triple-single-quoted docstrings. Pydoc will search any
module in site-packages at least, so you have to consider
third-party modules.

At best pydoc is inconsistent - the web browser display uses
the __doc__attribute but search and apropos use synopsis().
It's a pretty simple change to recognize any triple-quoted
string, it seems like a good idea to me...

I have attached a revised patch that uses a regex match so
it works with e.g. uR""" and other variations of triple-quoting.

FWIW this bug report was motivated by this thread on
comp.lang.python:
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/e5cfccb7c9a168d7/1c1702e71e1939b0?q=triple&rnum=1#1c1702e71e1939b0
msg25052 - (view) Author: Ka-Ping Yee (ping) * (Python committer) Date: 2005-04-18 20:28
Logged In: YES 
user_id=45338

I think you're right that if it works for the module summary
(using __doc__) then it should work with synopsis(). 
However, the patch you've added doesn't address the problem
properly; instead of handling """ correctly and ignoring
''', it handles both kinds of docstrings incorrectly because
it will accept ''' as a match for """ or """ as a match for '''.

I'll look at fixing this soon, but feel free to keep
prodding me until it gets fixed.
msg25053 - (view) Author: Brian vdB (brianvanden) Date: 2005-04-19 17:11
Logged In: YES 
user_id=1015686

I started the thread to which Kent referred. I am aware of
PEP 257's recommendation of triple-double quotes. My
(perhaps wrong-headed) construal of that PEP is that it
isn't sufficiently rule-giving that I would have expected
other tools to reject triple-single quotes. 
At any rate, since triple-single are syntactically
acceptable, it would seem better if they were accepted on
equal footing with triple-double. I can well understand that
this would be a v. low priority issue, though. Call it a
RFE. :-)
msg82175 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-02-15 22:16
Source still has the snippet in patch (didn't test behavior).
History
Date User Action Args
2010-08-21 13:50:23BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2010-06-02 08:40:03eric.araujosetnosy: + eric.araujo
2009-04-22 14:44:39ajaksu2setkeywords: + easy
2009-02-15 22:16:29ajaksu2setnosy: + ajaksu2
stage: test needed
type: behavior
messages: + msg82175
versions: + Python 2.6, - Python 2.4
2005-04-18 12:18:39kjohnsoncreate