Skip to content

Commit 365556c

Browse files
committed
Alternative approach: do not raise, just ignore the cast
1 parent a2babb4 commit 365556c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Lib/test/test_property.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,11 @@ def __new__(typ, *args, **kwargs):
410410
return "abcdef"
411411

412412
p = property.__new__(pro)
413-
with self.assertRaises(TypeError):
414-
p.getter(lambda self: 1) # this line was causing a crash
415-
with self.assertRaises(TypeError):
416-
p.setter(lambda self, val: 1) # this line was causing a crash
417-
with self.assertRaises(TypeError):
418-
p.deleter(lambda self: 1) # this line was causing a crash
413+
414+
# These lines were causing crashes:
415+
p.getter(lambda self: 1)
416+
p.setter(lambda self, val: 1)
417+
p.deleter(lambda self: 1)
419418

420419

421420
class _PropertyUnreachableAttribute:

Objects/descrobject.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,13 +1711,11 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
17111711
Py_DECREF(type);
17121712
if (new == NULL)
17131713
return NULL;
1714-
if (!PyObject_TypeCheck(new, &PyProperty_Type)) {
1715-
PyErr_Format(PyExc_TypeError, "property instance expected, got %.50s",
1716-
Py_TYPE(new)->tp_name);
1717-
return NULL;
1714+
if (PyObject_TypeCheck(new, &PyProperty_Type)) {
1715+
Py_XSETREF(((propertyobject *) new)->prop_name,
1716+
Py_XNewRef(pold->prop_name));
17181717
}
17191718

1720-
Py_XSETREF(((propertyobject *) new)->prop_name, Py_XNewRef(pold->prop_name));
17211719
return new;
17221720
}
17231721

0 commit comments

Comments
 (0)