[Python-bugs-list] [ python-Bugs-530070 ] pydoc regression

noreply@sourceforge.net noreply@sourceforge.net
Fri, 12 Apr 2002 04:31:02 -0700


Bugs item #530070, was opened at 2002-03-15 06: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: Closed
Resolution: Accepted
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: James Henstridge (jhenstridge)
Date: 2002-04-12 19:30

Message:
Logged In: YES 
user_id=146903

Please reconsider this patch.  My patch in bug #504343 was
designed to let me use a descriptor for the __doc__
attribute of some of my classes in PyGTK.

I add some information in the docstrings is looked up via
introspection (so that it is in sync with the objects I am
wrapping, and also to avoid the startup overhead), which is
why I wanted to use a descriptor.

Your patch means that all classes (which are non heap type)
now return None when instead of calling the descriptor.  For
heap type classes, it won't call the descriptor's
tp_descr_get() method if __doc__ happens to be a descriptor
-- instead returning the descriptor itself.

Would it be possible to reconsider this fix?  If not for
2.2.1, at least for 2.3.  Maybe just adding an extra str()
call in pydoc/inspect would fix the problem.

Being able to use descriptors for the __doc__ attribute in
order to load docs lazily may be useful for other purposes
as well (not just pygtk).

Would it be better open a new bug for this, or reopen this
report?

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-18 03:00

Message:
Logged In: YES 
user_id=31435

I applied type2.txt and inspect3.txt to the trunk and to 
release22-maint.  If you believe there are other bugs here 
that need fixing day, please open new bug reports.

Lib/inspect.py
    new revision: 1.28
    new revision: 1.26.10.2
Objects/typeobject.c
    new revision: 2.130
    new revision: 2.126.4.4

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-16 02: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-16 02: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-16 02: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-16 02: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-16 01: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 23: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 17: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-15 08: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-15 08: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