From: Benjamin Peterson Date: Tue, 19 Jan 2016 05:11:18 +0000 (-0800) Subject: set tp_new from the class in the hierarchy that actually owns the descriptor (closes... X-Git-Tag: v3.6.0a1~740^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ad11544bfb80b7881e0d567e40ef2fa2da58f02;p=python set tp_new from the class in the hierarchy that actually owns the descriptor (closes #25731) Debugging by Eryk Sun. --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index f5e4b02b7b..a8206d3146 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4564,6 +4564,14 @@ order (MRO) for bases """ self.assertRegex(repr(method), r">") + def test_deleting_new_in_subclasses(self): + class X: + def __init__(self, a): + pass + X.__new__ = None + del X.__new__ + X(1) # should work + class DictProxyTests(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index 69441424f1..b6e8fe1b90 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Release date: tba Core and Builtins ----------------- +- Issue #25731: Fix set and deleting __new__ on a class. + - Issue #22995: [UPDATE] Comment out the one of the pickleability tests in _PyObject_GetState() due to regressions observed in Cython-based projects. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 415f91689f..810afd3d61 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6777,7 +6777,7 @@ update_one_slot(PyTypeObject *type, slotdef *p) sanity checks and constructing a new argument list. Cut all that nonsense short -- this speeds up instance creation tremendously. */ - specific = (void *)type->tp_new; + specific = (void *)((PyTypeObject *)PyCFunction_GET_SELF(descr))->tp_new; /* XXX I'm not 100% sure that there isn't a hole in this reasoning that requires additional sanity checks. I'll buy the first person to