Skip to content

Commit

Permalink
Changed the way __doc__ is managed to get backward compatible behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Sep 30, 2004
1 parent 7b0b0cf commit a3c0172
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions _ExtensionClass.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ EC_init(PyTypeObject *self, PyObject *args, PyObject *kw)
if (PyType_Type.tp_init(OBJECT(self), args, kw) < 0)
return -1;

if (self->tp_dict != NULL)
{
r = PyDict_GetItemString(self->tp_dict, "__doc__");
if ((r == Py_None) &&
(PyDict_DelItemString(self->tp_dict, "__doc__") < 0)
)
return -1;
}

/* set up __get__, if necessary */
if (self->tp_descr_get != of_get)
{
Expand Down
19 changes: 19 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def test__basicnew__():
{}
"""



def cmpattrs(self, other, *attrs):
for attr in attrs:
if attr[:3] in ('_v_', '_p_'):
Expand Down Expand Up @@ -690,6 +692,23 @@ def test_of_not_called_when_not_accessed_through_EC_instance():
"""

def test_inheriting___doc__():
"""Old-style ExtensionClass inherited __doc__ from base classes.
>>> class E(Base):
... "eek"
>>> class EE(E):
... pass
>>> EE.__doc__
'eek'
>>> EE().__doc__
'eek'
"""

from doctest import DocTestSuite
import unittest

Expand Down

0 comments on commit a3c0172

Please sign in to comment.