mirror of https://github.com/python/cpython.git
[3.11] GH-100942: Fix incorrect cast in property_copy(). (GH-100965). (#101008)
(cherry picked from commit 94fc7706b7
)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
parent
6d98282ed4
commit
855b1a935e
|
@ -214,6 +214,23 @@ def test_property_set_name_incorrect_args(self):
|
||||||
):
|
):
|
||||||
p.__set_name__(*([0] * i))
|
p.__set_name__(*([0] * i))
|
||||||
|
|
||||||
|
def test_property_setname_on_property_subclass(self):
|
||||||
|
# https://github.com/python/cpython/issues/100942
|
||||||
|
# Copy was setting the name field without first
|
||||||
|
# verifying that the copy was an actual property
|
||||||
|
# instance. As a result, the code below was
|
||||||
|
# causing a segfault.
|
||||||
|
|
||||||
|
class pro(property):
|
||||||
|
def __new__(typ, *args, **kwargs):
|
||||||
|
return "abcdef"
|
||||||
|
|
||||||
|
class A:
|
||||||
|
pass
|
||||||
|
|
||||||
|
p = property.__new__(pro)
|
||||||
|
p.__set_name__(A, 1)
|
||||||
|
np = p.getter(lambda self: 1)
|
||||||
|
|
||||||
# Issue 5890: subclasses of property do not preserve method __doc__ strings
|
# Issue 5890: subclasses of property do not preserve method __doc__ strings
|
||||||
class PropertySub(property):
|
class PropertySub(property):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed segfault in property.getter/setter/deleter that occurred when a property
|
||||||
|
subclass overrode the ``__new__`` method to return a non-property instance.
|
|
@ -1723,9 +1723,10 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (PyObject_TypeCheck((new), &PyProperty_Type)) {
|
||||||
Py_XINCREF(pold->prop_name);
|
Py_XINCREF(pold->prop_name);
|
||||||
Py_XSETREF(((propertyobject *) new)->prop_name, pold->prop_name);
|
Py_XSETREF(((propertyobject *) new)->prop_name, pold->prop_name);
|
||||||
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue