]> granicus.if.org Git - python/commitdiff
set tp_new from the class in the hierarchy that actually owns the descriptor (closes...
authorBenjamin Peterson <benjamin@python.org>
Tue, 19 Jan 2016 05:11:18 +0000 (21:11 -0800)
committerBenjamin Peterson <benjamin@python.org>
Tue, 19 Jan 2016 05:11:18 +0000 (21:11 -0800)
Debugging by Eryk Sun.

Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index f5e4b02b7b6b4ce5bfad9b376e3eb35a67fe8455..a8206d3146df09d688754c771a064f21c9924467 100644 (file)
@@ -4564,6 +4564,14 @@ order (MRO) for bases """
         self.assertRegex(repr(method),
             r"<bound method qualname of <object object at .*>>")
 
+    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):
index 69441424f1aaa6b6e0daf56c4fc3adc4f9076f59..b6e8fe1b900ba7f05d64f09b71ed14be2f0558b7 100644 (file)
--- 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.
 
index 415f91689f66a7728a7157ea74d66a3cc791a86f..810afd3d610b48c01b09a7287763629595286323 100644 (file)
@@ -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