[pypy-commit] pypy default: merge heads

arigo pypy.commits at gmail.com
Thu Oct 27 18:10:21 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r87965:14a2e7623816
Date: 2016-10-27 23:19 +0100
http://bitbucket.org/pypy/pypy/changeset/14a2e7623816/

Log:	merge heads

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/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -73,11 +73,8 @@
             exc_value = str(w_value)
         else:
             w = space.wrap
-            if space.is_w(space.type(self.w_type), space.w_str):
-                exc_typename = space.str_w(self.w_type)
-            else:
-                exc_typename = space.str_w(
-                    space.getattr(self.w_type, w('__name__')))
+            exc_typename = space.str_w(
+                space.getattr(self.w_type, w('__name__')))
             if space.is_w(w_value, space.w_None):
                 exc_value = ""
             else:
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -611,7 +611,7 @@
 
 class StaticMethod(W_Root):
     """The staticmethod objects."""
-    _immutable_fields_ = ['w_function']
+    _immutable_fields_ = ['w_function?']
 
     def __init__(self, w_function):
         self.w_function = w_function
@@ -622,13 +622,16 @@
 
     def descr_staticmethod__new__(space, w_subtype, w_function):
         instance = space.allocate_instance(StaticMethod, w_subtype)
-        instance.__init__(w_function)
-        return space.wrap(instance)
+        instance.__init__(space.w_None)
+        return instance
+
+    def descr_init(self, space, w_function):
+        self.w_function = w_function
 
 
 class ClassMethod(W_Root):
     """The classmethod objects."""
-    _immutable_fields_ = ['w_function']
+    _immutable_fields_ = ['w_function?']
 
     def __init__(self, w_function):
         self.w_function = w_function
@@ -641,8 +644,11 @@
 
     def descr_classmethod__new__(space, w_subtype, w_function):
         instance = space.allocate_instance(ClassMethod, w_subtype)
-        instance.__init__(w_function)
-        return space.wrap(instance)
+        instance.__init__(space.w_None)
+        return instance
+
+    def descr_init(self, space, w_function):
+        self.w_function = w_function
 
 class FunctionWithFixedCode(Function):
     can_change_code = False
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -686,15 +686,17 @@
 (e.g. C().f()).  The instance is ignored except for its class.""",
     __get__ = interp2app(StaticMethod.descr_staticmethod_get),
     __new__ = interp2app(StaticMethod.descr_staticmethod__new__.im_func),
+    __init__=interp2app(StaticMethod.descr_init),
     __func__= interp_attrproperty_w('w_function', cls=StaticMethod),
     )
 
 ClassMethod.typedef = TypeDef(
     'classmethod',
-    __new__ = interp2app(ClassMethod.descr_classmethod__new__.im_func),
-    __get__ = interp2app(ClassMethod.descr_classmethod_get),
-    __func__= interp_attrproperty_w('w_function', cls=ClassMethod),
-    __doc__ = """classmethod(function) -> class method
+    __new__=interp2app(ClassMethod.descr_classmethod__new__.im_func),
+    __init__=interp2app(ClassMethod.descr_init),
+    __get__=interp2app(ClassMethod.descr_classmethod_get),
+    __func__=interp_attrproperty_w('w_function', cls=ClassMethod),
+    __doc__="""classmethod(function) -> class method
 
 Convert a function to be a class method.
 
diff --git a/pypy/module/__builtin__/test/test_descriptor.py b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -20,6 +20,12 @@
         x = Static(1)
         assert isinstance(x, Static)
 
+        class C(Static):
+            def __init__(self, callable):
+                super(C, self).__init__(callable)
+        y = C(1)
+        assert isinstance(y, C)
+
     def test_classmethod(self):
         class C(object):
             def f(cls, stuff):
@@ -41,8 +47,14 @@
         x = Classm(1)
         assert isinstance(x, Classm)
 
+        class C(Classm):
+            def __init__(self, callable):
+                super(C, self).__init__(callable)
+        y = C(1)
+        assert isinstance(y, C)
+
     def test_property_simple(self):
-        
+
         class a(object):
             def _get(self): return 42
             def _set(self, value): raise AttributeError
@@ -98,7 +110,7 @@
             assert message.startswith('super(type, obj): obj must be an instance or subtype of type')
 
     def test_super_various(self):
-        
+
         class A(object):
             def meth(self, a):
                 return "A(%r)" % a
@@ -352,10 +364,10 @@
 
     def test_property_subclass_with_init(self):
         l = []
-        
+
         def x(self):
             l.append('x')
-        
+
         class P(property):
             def __init__(self):
                 property.__init__(self, x)
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):
+            # 2.7: warn about excess arguments when both methods are
+            # overridden
+            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):
             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")
 
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -249,6 +249,7 @@
     SEEK_SET = rffi_platform.DefinedConstantInteger('SEEK_SET')
     SEEK_CUR = rffi_platform.DefinedConstantInteger('SEEK_CUR')
     SEEK_END = rffi_platform.DefinedConstantInteger('SEEK_END')
+    O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK')
     OFF_T_SIZE = rffi_platform.SizeOf('off_t')
 
     HAVE_UTIMES = rffi_platform.Has('utimes')
@@ -2353,3 +2354,42 @@
 
 def cpu_count():
     return rffi.cast(lltype.Signed, _cpu_count())
+
+if not _WIN32:
+    eci_status_flags = eci.merge(ExternalCompilationInfo(separate_module_sources=["""
+    RPY_EXTERN
+    int rpy_get_status_flags(int fd)
+    {
+        int flags;
+        flags = fcntl(fd, F_GETFL, 0);
+        return flags;
+    }
+
+    RPY_EXTERN
+    int rpy_set_status_flags(int fd, int flags)
+    {
+        int res;
+        res = fcntl(fd, F_SETFL, flags);
+        return res;
+    }
+    """], post_include_bits=[
+        "RPY_EXTERN int rpy_get_status_flags(int);\n"
+        "RPY_EXTERN int rpy_set_status_flags(int, int);"]
+    ))
+
+
+    c_get_status_flags = external('rpy_get_status_flags', [rffi.INT],
+                                rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO,
+                                compilation_info=eci_status_flags)
+    c_set_status_flags = external('rpy_set_status_flags', [rffi.INT, rffi.INT],
+                                rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO,
+                                compilation_info=eci_status_flags)
+
+    def get_status_flags(fd):
+        res = c_get_status_flags(fd)
+        res = handle_posix_error('get_status_flags', res)
+        return res
+
+    def set_status_flags(fd, flags):
+        res = c_set_status_flags(fd, flags)
+        handle_posix_error('set_status_flags', res)
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -612,3 +612,15 @@
 def test_cpu_count():
     cc = rposix.cpu_count()
     assert cc >= 1
+
+ at rposix_requires('set_status_flags')
+def test_set_status_flags():
+    fd1, fd2 = os.pipe()
+    try:
+        flags = rposix.get_status_flags(fd1)
+        assert flags & rposix.O_NONBLOCK == 0
+        rposix.set_status_flags(fd1, flags | rposix.O_NONBLOCK)
+        assert rposix.get_status_flags(fd1) & rposix.O_NONBLOCK != 0
+    finally:
+        os.close(fd1)
+        os.close(fd2)


More information about the pypy-commit mailing list