Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,19 @@ def spam(self):
return 2
self.assertEqual(Foo.spam.__doc__, "a new docstring")

def test_gh100942(self):
# See https://github.com/python/cpython/issues/100942
class pro(property):
def __new__(typ, *args, **kwargs):
return "abcdef"

p = property.__new__(pro)

# These lines were causing crashes:
p.getter(lambda self: 1)
p.setter(lambda self, val: 1)
p.deleter(lambda self: 1)


class _PropertyUnreachableAttribute:
msg_format = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash on ``property`` subclasses with weird ``__new__`` methods.
5 changes: 4 additions & 1 deletion Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,11 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
Py_DECREF(type);
if (new == NULL)
return NULL;
if (PyObject_TypeCheck(new, &PyProperty_Type)) {
Py_XSETREF(((propertyobject *) new)->prop_name,
Py_XNewRef(pold->prop_name));
}

Py_XSETREF(((propertyobject *) new)->prop_name, Py_XNewRef(pold->prop_name));
return new;
}

Expand Down