-
- Notifications
You must be signed in to change notification settings - Fork 33.6k
Closed
Labels
3.12only security fixesonly security fixestopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
property's tp_init has this code:
if (Py_IS_TYPE(self, &PyProperty_Type)) { Py_XSETREF(self->prop_doc, prop_doc); } else { /* If this is a property subclass, put __doc__ in dict of the subclass instance instead, otherwise it gets shadowed by __doc__ in the class's dict. */ /*...*/ PyObject_SetAttr((PyObject *)self, &_Py_ID(__doc__), prop_doc); /*...*/ } This assumes that subclasses of property have a __dict__ (or a __doc__ attribute settable by other means). That is the case when subclassed using the class statement, but might not be true using C.
A C-API reproducer is at https://github.com/wjakob/inheritance_issue/blob/master/inheritance_issue.c
I don't see a good way to fix this. We could:
- document that subclasses need to set
Py_TPFLAGS_MANAGED_DICT(or provide a__doc__descriptor), or - ignore the
AttributeError, unless__doc__was set explicitly?
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixestopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error