[Python-bugs-list] [ python-Bugs-507394 ] non-string __doc__/new style class prob.

noreply@sourceforge.net noreply@sourceforge.net
Tue, 22 Jan 2002 23:33:14 -0800


Bugs item #507394, was opened at 2002-01-22 23:33
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=507394&group_id=5470

Category: Type/class unification
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: James Henstridge (jhenstridge)
Assigned to: Nobody/Anonymous (nobody)
Summary: non-string __doc__/new style class prob.

Initial Comment:
I have some new style classes in one of my packages,
and wanted to use something other than a string for
their __doc__ attributes (a descriptor, actually -- I
want to lazily look up some docs via introspection). 
Unfortunately, it looks like reading "type.__doc__"
will return None unless the __doc__ attribute was a
string at class creation time.

This seems to be because the type.__doc__ property
takes precedence, and it just checks the tp_doc slot in
the type's vtable.  As __doc__ wasn't a string,
type_new() leaves tp_doc as NULL.

I have attached a small test program to demonstrate the
problem.  Its output is as follows:

OldClass.__doc__   = 'object=None             
type=OldClass'
OldClass().__doc__ = 'object=OldClass instance
type=OldClass'
NewClass.__doc__   = None
NewClass().__doc__ = 'object=NewClass instance
type=NewClass'

Ideally, NewClass.__doc__ would give a similar result
to OldClass.__doc__.

One way to fix this might be to get rid of the
type.__doc__ property, and set __doc__ in the class
dictionary from tp_doc (if it is non NULL) during
PyType_Ready().

James Henstridge <james daa com au>


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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=507394&group_id=5470