[Python-bugs-list] [ python-Bugs-530070 ] pydoc regression
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 15 Mar 2002 10:55:24 -0800
Bugs item #530070, was opened at 2002-03-14 17:35
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=530070&group_id=5470
Category: Python Library
Group: Python 2.2.1 candidate
Status: Open
Resolution: None
Priority: 7
Submitted By: Tim Peters (tim_one)
Assigned to: Tim Peters (tim_one)
Summary: pydoc regression
Initial Comment:
In current CVS trunk and release22-maint branch:
C:\Pyt>python
Python 2.2.1a1 (#32, Mar 14 2002, 14:10:11) [MSC 32
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import __builtin__
>>> help(__builtin__)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Pyt\lib\site.py", line 279, in __call__
return pydoc.help(*args, **kwds)
File "C:\Pyt\lib\pydoc.py", line 1509, in __call__
self.help(request)
File "C:\Pyt\lib\pydoc.py", line 1545, in help
else: doc(request, 'Help on %s:')
File "C:\Pyt\lib\pydoc.py", line 1340, in doc
pager(title % (desc + suffix) + '\n\n' +
text.document(thing, name))
File "C:\Pyt\lib\pydoc.py", line 267, in document
if inspect.ismodule(object): return apply
(self.docmodule, args)
File "C:\Pyt\lib\pydoc.py", line 960, in docmodule
contents.append(self.document(value, key, name))
File "C:\Pyt\lib\pydoc.py", line 268, in document
if inspect.isclass(object): return apply
(self.docclass, args)
File "C:\Pyt\lib\pydoc.py", line 1005, in docclass
doc = getdoc(object)
File "C:\Pyt\lib\pydoc.py", line 66, in getdoc
result = inspect.getdoc(object) or
inspect.getcomments(object)
File "C:\Pyt\lib\inspect.py", line 267, in getdoc
lines = string.split(string.expandtabs
(object.__doc__), '\n')
File "C:\Pyt\lib\string.py", line 298, in expandtabs
return s.expandtabs(tabsize)
AttributeError: 'member_descriptor' object has no
attribute 'expandtabs'
>>>
help(__builtin__) worked in 2.2. Trying to browse the
__builtin__ module from GUI pydoc crashes pydoc for
the same reason.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-15 13:55
Message:
Logged In: YES
user_id=6380
Indeed, but that's a different problem worthy of a separate
bug report. It happens in the unpatched code too, so I don't
think it is a result of my patch -- it just so happens that
your patch also addressed this. But I believe getdoc()
should work for Unicode strings just fine.
I've uploaded inspect3.txt which addresses a different
cosmetic issue but is otherwise the same as inspect2.txt.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2002-03-15 13:42
Message:
Logged In: YES
user_id=21627
Your inspect patch has undesirable results. Given
class Foo:
u"Autor: v. Löwis"
help(Foo) will produce a UnicodeError. This is undesirable,
IMO - it should better just ignore the doc string.
It may be sensible to ignore this for now, hoping that
output devices which support full Unicode become available
(actually, the pydoc web server, can, in principle, support
this case well).
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-15 13:27
Message:
Logged In: YES
user_id=6380
I've appended a better version (IMO) of the inspect patch.
I find it ugly to have to catch UnicodeError with a comment
explaining it. My version (inspect2.txt) leaves nothing to
the imagination. It also makes sure that there's an explicit
return in each path through the function.
Random gripe: why doesn't inspect.py use string methods? The
string module looks soooooooo dorky...
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-03-15 13:14
Message:
Logged In: YES
user_id=31435
Thanks, fellows! Let's leave this assigned to me. I'll
get to it over the weekend (if not toady).
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2002-03-15 12:39
Message:
Logged In: YES
user_id=21627
I recommend to guarantee that inspect.getdoc always returns
a string or None. The attached patch should cover all cases
discussed so far: if __doc__ is a non-string object, it will
produce a string version of it - somewhat ugly, but not
catastrophic. If it is a Unicode object, it will return
nothing if that does not convert into a byte string.
Together with Guido's patch, this should bring us back to
the 2.2 state.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-15 10:07
Message:
Logged In: YES
user_id=6380
Hm, that doesn't solve all cases. E.g.
types.FunctionType.__doc__ is None in 2.2, but returns a
descriptor in current CVS, and still after your patch.
I've attached a new patch that looks at the HEAPTYPE flag.
When the HEAPTYPE flag is clear, it's a type defined in C,
and we should believe tp_doc. When HEAPTYPE is set, it's a
new-style class defined in Python, and we should believe
__dict__['__doc__'].
But pydoc is still broken, and needs to be fixed, because
one could define a type in Python that has a __doc__
descriptor for its instances, and then pydoc would still do
the wrong thing.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2002-03-15 04:57
Message:
Logged In: YES
user_id=21627
This was changed with typeobject.c 2.127, which changed
__doc__ access to always look into the __dict__ and never
into tp_doc, to allow for Unicode doc strings.
The attached patch partially reverts this change: it now
duplicates tp_doc if present, and only returns
__dict__['__doc__'] if tp_doc is NULL.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-03-14 19:48
Message:
Logged In: YES
user_id=31435
Well, it's obviously not expected by pydoc <wink>. In 2.2,
__builtin__.property.__doc__ was a string. I've no idea
why it changed, but it doesn't smell right to me. Maybe
Guido knows? Assigning to him just in case.
----------------------------------------------------------------------
Comment By: A.M. Kuchling (akuchling)
Date: 2002-03-14 19:13
Message:
Logged In: YES
user_id=11375
The fundamental problem is that __builtin__.property.__doc__
returns an object of type 'member_descriptor', not a string.
Is that
expected?
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=530070&group_id=5470