FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-100942: Fix crash on `property` subtypes with weird `__new__` by sobolevn · Pull Request #100955 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions Lib/test/test_property.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL