[pypy-commit] pypy default: merge branch newinitwarn:

pjenvey pypy.commits at gmail.com
Tue Oct 25 00:32:49 EDT 2016


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: 
Changeset: r87924:9ca2422664c4
Date: 2016-10-24 21:31 -0700
http://bitbucket.org/pypy/pypy/changeset/9ca2422664c4/

Log:	merge branch newinitwarn:

	issue warnings for stricter handling of __new/init__ args (that
	become TypeErrors in python 3)

	issue #2306

diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py
--- a/lib_pypy/_collections.py
+++ b/lib_pypy/_collections.py
@@ -29,7 +29,7 @@
 class deque(object):
 
     def __new__(cls, iterable=(), *args, **kw):
-        self = super(deque, cls).__new__(cls, *args, **kw)
+        self = super(deque, cls).__new__(cls)
         self.clear()
         return self
 
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -229,7 +229,7 @@
     __metaclass__ = StructOrUnionMeta
 
     def __new__(cls, *args, **kwds):
-        self = super(_CData, cls).__new__(cls, *args, **kwds)
+        self = super(_CData, cls).__new__(cls)
         if '_abstract_' in cls.__dict__:
             raise TypeError("abstract class")
         if hasattr(cls, '_ffistruct_'):
diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -91,11 +91,17 @@
     from pypy.objspace.std.typeobject import _precheck_for_new
     w_type = _precheck_for_new(space, w_type)
 
-    # don't allow arguments if the default object.__init__() is about
-    # to be called
     if _excess_args(__args__):
+        w_parent_new, _ = space.lookup_in_type_where(w_type, '__new__')
         w_parent_init, _ = space.lookup_in_type_where(w_type, '__init__')
-        if w_parent_init is space.w_object:
+        if (w_parent_new is not space.w_object and
+            w_parent_init is not space.w_object):
+            space.warn(space.wrap("object() takes no parameters"),
+                       space.w_DeprecationWarning, 1)
+        elif (w_parent_new is not space.w_object or
+              w_parent_init is space.w_object):
+            # 2.7: warn about excess arguments when both methods are
+            # overridden
             raise oefmt(space.w_TypeError,
                         "object() takes no parameters")
     if w_type.is_abstract():
@@ -108,11 +114,18 @@
 
 
 def descr__init__(space, w_obj, __args__):
-    # don't allow arguments unless __new__ is overridden
     if _excess_args(__args__):
         w_type = space.type(w_obj)
+        w_parent_init, _ = space.lookup_in_type_where(w_type, '__init__')
         w_parent_new, _ = space.lookup_in_type_where(w_type, '__new__')
-        if w_parent_new is space.w_object:
+        if (w_parent_init is not space.w_object and
+            w_parent_new is not space.w_object):
+            # 2.7: warn about excess arguments when both methods are
+            # overridden
+            space.warn(space.wrap("object.__init__() takes no parameters"),
+                       space.w_DeprecationWarning, 1)
+        elif (w_parent_init is not space.w_object or
+              w_parent_new is space.w_object):
             raise oefmt(space.w_TypeError,
                         "object.__init__() takes no parameters")
 


More information about the pypy-commit mailing list