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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 25 Jan 2002 10:10:13 -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: Closed
>Resolution: Duplicate
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>


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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-01-25 10:09

Message:
Logged In: YES 
user_id=6380

This is a duplicate of #504343 Unicode docstrings and new
style classes.
Please see if the fix there works for you, and add a comment
there to saif whether it does. Then I can check it in.

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

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