Author: Richard Plangger <planri...@gmail.com>
Branch: py3.5-ssl
Changeset: r88948:a94a5155d64a
Date: 2016-12-07 16:31 +0100
http://bitbucket.org/pypy/pypy/changeset/a94a5155d64a/

Log:    merge py3.5

diff --git a/lib-python/3/test/test_builtin.py 
b/lib-python/3/test/test_builtin.py
--- a/lib-python/3/test/test_builtin.py
+++ b/lib-python/3/test/test_builtin.py
@@ -16,7 +16,8 @@
 import warnings
 from operator import neg
 from test.support import (
-    TESTFN, unlink,  run_unittest, check_warnings, check_impl_detail)
+    TESTFN, unlink,  run_unittest, check_warnings, check_impl_detail,
+    cpython_only)
 from test.support.script_helper import assert_python_ok
 try:
     import pty, signal
@@ -1640,6 +1641,8 @@
 
 class ShutdownTest(unittest.TestCase):
 
+    # PyPy doesn't do a gc.collect() at shutdown
+    @cpython_only
     def test_cleanup(self):
         # Issue #19255: builtins are still available at shutdown
         code = """if 1:
diff --git a/lib-python/3/test/test_exceptions.py 
b/lib-python/3/test/test_exceptions.py
--- a/lib-python/3/test/test_exceptions.py
+++ b/lib-python/3/test/test_exceptions.py
@@ -1049,6 +1049,7 @@
                 obj = test_class()
                 with captured_stderr() as stderr:
                     del obj
+                    gc_collect()
                 report = stderr.getvalue()
                 self.assertIn("Exception ignored", report)
                 if test_class is BrokenRepr:
@@ -1059,7 +1060,12 @@
                 self.assertIn("raise exc", report)
                 if test_class is BrokenExceptionDel:
                     self.assertIn("BrokenStrException", report)
-                    self.assertIn("<exception str() failed>", report)
+                    if check_impl_detail(pypy=False):
+                        self.assertIn("<exception str() failed>", report)
+                    else:
+                        # pypy: this is what lib-python's traceback.py gives
+                        self.assertIn("<unprintable BrokenExceptionDel 
object>",
+                                      report)
                 else:
                     self.assertIn("ValueError", report)
                     self.assertIn("del is broken", report)
@@ -1081,7 +1087,12 @@
                 self.assertIn("raise exc", report)
                 self.assertIn(exc_type.__name__, report)
                 if exc_type is BrokenStrException:
-                    self.assertIn("<exception str() failed>", report)
+                    if check_impl_detail(pypy=False):
+                        self.assertIn("<exception str() failed>", report)
+                    else:
+                        # pypy: this is what lib-python's traceback.py gives
+                        self.assertIn("<unprintable BrokenStrException 
object>",
+                                      report)
                 else:
                     self.assertIn("test message", report)
                 self.assertTrue(report.endswith("\n"))
diff --git a/lib-python/3/test/test_super.py b/lib-python/3/test/test_super.py
--- a/lib-python/3/test/test_super.py
+++ b/lib-python/3/test/test_super.py
@@ -105,14 +105,16 @@
                 def f():
                     __class__""", globals(), {})
         self.assertIs(type(e.exception), NameError) # Not UnboundLocalError
-        class X:
-            global __class__
-            __class__ = 42
-            def f():
-                __class__
-        self.assertEqual(globals()["__class__"], 42)
-        del globals()["__class__"]
-        self.assertNotIn("__class__", X.__dict__)
+        # XXX the following uses 'global __class__', which pypy doesn't
+        # XXX implement at all for now
+        #class X:
+        #    global __class__
+        #    __class__ = 42
+        #    def f():
+        #        __class__
+        #self.assertEqual(globals()["__class__"], 42)
+        #del globals()["__class__"]
+        #self.assertNotIn("__class__", X.__dict__)
         class X:
             nonlocal __class__
             __class__ = 42
diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
--- a/lib_pypy/audioop.py
+++ b/lib_pypy/audioop.py
@@ -375,7 +375,7 @@
     sample_count = _sample_count(cp, size)
 
     rv = ffi.new("unsigned char[]", len(cp) * 2)
-    lib.tostereo(rv, cp, len(cp), size, fac1, fac2)
+    lib.tostereo(rv, ffi.from_buffer(cp), len(cp), size, fac1, fac2)
     return ffi.buffer(rv)[:]
 
 
@@ -386,7 +386,7 @@
         raise error("Lengths should be the same")
 
     rv = ffi.new("unsigned char[]", len(cp1))
-    lib.add(rv, cp1, cp2, len(cp1), size)
+    lib.add(rv, ffi.from_buffer(cp1), ffi.from_buffer(cp2), len(cp1), size)
     return ffi.buffer(rv)[:]
 
 
@@ -569,7 +569,7 @@
     state = _check_state(state)
     rv = ffi.new("unsigned char[]", len(cp) * size * 2)
     state_ptr = ffi.new("int[]", state)
-    lib.adcpm2lin(rv, cp, len(cp), size, state_ptr)
+    lib.adcpm2lin(rv, ffi.from_buffer(cp), len(cp), size, state_ptr)
     return ffi.buffer(rv)[:], tuple(state_ptr)
 
 def byteswap(cp, size):
diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -137,11 +137,11 @@
         return ''.join(code)
 
 
-def _make_index_dict_filter(syms, flag):
+def _make_index_dict_filter(syms, flag1, flag2):
     i = 0
     result = {}
     for name, scope in syms.iteritems():
-        if scope == flag:
+        if scope in (flag1, flag2):
             result[name] = i
             i += 1
     return result
@@ -170,7 +170,8 @@
         self.names = {}
         self.var_names = _iter_to_dict(scope.varnames)
         self.cell_vars = _make_index_dict_filter(scope.symbols,
-                                                 symtable.SCOPE_CELL)
+                                                 symtable.SCOPE_CELL,
+                                                 symtable.SCOPE_CELL_CLASS)
         self.free_vars = _iter_to_dict(scope.free_vars, len(self.cell_vars))
         self.w_consts = space.newdict()
         self.argcount = 0
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -317,7 +317,8 @@
             # Load cell and free vars to pass on.
             for free in code.co_freevars:
                 free_scope = self.scope.lookup(free)
-                if free_scope == symtable.SCOPE_CELL:
+                if free_scope in (symtable.SCOPE_CELL,
+                                  symtable.SCOPE_CELL_CLASS):
                     index = self.cell_vars[free]
                 else:
                     index = self.free_vars[free]
@@ -1626,7 +1627,7 @@
         self._handle_body(cls.body)
         # return the (empty) __class__ cell
         scope = self.scope.lookup("__class__")
-        if scope == symtable.SCOPE_CELL:
+        if scope == symtable.SCOPE_CELL_CLASS:
             # Return the cell where to store __class__
             self.emit_op_arg(ops.LOAD_CLOSURE, self.cell_vars["__class__"])
         else:
diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -21,6 +21,7 @@
 SCOPE_LOCAL = 3
 SCOPE_FREE = 4
 SCOPE_CELL = 5
+SCOPE_CELL_CLASS = 6     # for "__class__" inside class bodies only
 
 
 class Scope(object):
@@ -336,7 +337,7 @@
     def _finalize_cells(self, free):
         for name, role in self.symbols.iteritems():
             if role == SCOPE_LOCAL and name in free and name == '__class__':
-                self.symbols[name] = SCOPE_CELL
+                self.symbols[name] = SCOPE_CELL_CLASS
                 del free[name]
 
 
diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -398,6 +398,13 @@
     # in CPython 3.5.2.  Looks like a bug to me
 def testing():
     return 42
+''', '''
+class Y:
+    def f():
+        __class__
+    __class__ = 42
+def testing():
+    return Y.__dict__['__class__']
 '''
         ]:
             space.call_args(w_filterwarnings, filter_arg)
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -80,7 +80,8 @@
 
 class statvfs_result(metaclass=structseqtype):
 
-    name = osname + ".statvfs_result"
+    name = "os.statvfs_result"
+    __module__ = "os"
 
     f_bsize = structseqfield(0)
     f_frsize = structseqfield(1)
@@ -96,7 +97,7 @@
 
 class uname_result(metaclass=structseqtype):
 
-    name = osname + ".uname_result"
+    name = osname + ".uname_result"    # and NOT "os.uname_result"
 
     sysname  = structseqfield(0, "operating system name")
     nodename = structseqfield(1, "name of machine on network "
@@ -108,6 +109,7 @@
 class terminal_size(metaclass=structseqtype):
 
     name = "os.terminal_size"
+    __module__ = "os"
 
     columns  = structseqfield(0, "width of the terminal window in characters")
     lines = structseqfield(1, "height of the terminal window in characters")
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -325,7 +325,7 @@
         if space.isinstance_w(w_path, space.w_int):
             w_fd = w_path
         else:
-            w_fd = open(space, w_path, os.O_RDWR | os.O_CREAT)
+            w_fd = open(space, w_path, os.O_WRONLY)
             allocated_fd = True
 
         fd = space.c_filedescriptor_w(w_fd)
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -1067,6 +1067,10 @@
             posix.truncate(dest, 1)
             assert 1 == posix.stat(dest).st_size
 
+            # File does not exist
+            e = raises(OSError, posix.truncate, dest + '-DOESNT-EXIST', 0)
+            assert e.value.filename == dest + '-DOESNT-EXIST'
+
     try:
         os.getlogin()
     except (AttributeError, OSError):
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -187,7 +187,7 @@
             return space.w_NotImplemented
 
         if w_exponent.asbigint().sign < 0:
-            raise oefmt(space.w_TypeError,
+            raise oefmt(space.w_ValueError,
                         "pow() 2nd argument cannot be negative when 3rd "
                         "argument specified")
         try:
diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -667,6 +667,11 @@
         b.abc = "awesomer"
         assert b.abc == "awesomer"
 
+    def test_bad_slots(self):
+        raises(TypeError, type, 'A', (), {'__slots__': b'x'})
+        raises(TypeError, type, 'A', (), {'__slots__': 42})
+        raises(TypeError, type, 'A', (), {'__slots__': '2_x'})
+
     def test_base_attr(self):
         # check the '__base__'
         class A(object):
@@ -936,6 +941,22 @@
         else:
             assert False
 
+    def test_qualname(self):
+        A = type('A', (), {'__qualname__': 'B.C'})
+        assert A.__name__ == 'A'
+        assert A.__qualname__ == 'B.C'
+        raises(TypeError, type, 'A', (), {'__qualname__': b'B'})
+        assert A.__qualname__ == 'B.C'
+
+        A.__qualname__ = 'D.E'
+        assert A.__name__ == 'A'
+        assert A.__qualname__ == 'D.E'
+
+        C = type('C', (), {})
+        C.__name__ = 'A'
+        assert C.__name__ == 'A'
+        assert C.__qualname__ == 'C'
+
     def test_compare(self):
         class A(object):
             pass
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -166,7 +166,7 @@
                  overridetypedef=None, force_new_layout=False):
         self.space = space
         self.name = name
-        self.qualname = None
+        self.qualname = name.decode('utf-8')
         self.bases_w = bases_w
         self.dict_w = dict_w
         self.hasdict = False
@@ -545,7 +545,7 @@
         return result.decode('utf-8')
 
     def getqualname(self, space):
-        return self.qualname or self.getname(space)
+        return self.qualname
 
     def add_subclass(self, w_subclass):
         space = self.space
@@ -1057,6 +1057,14 @@
         w_self.weakrefable = w_self.weakrefable or w_base.weakrefable
     return hasoldstylebase
 
+def slot_w(space, w_name):
+    from pypy.objspace.std.unicodeobject import _isidentifier
+    if not space.isinstance_w(w_name, space.w_text):
+        raise oefmt(space.w_TypeError,
+            "__slots__ items must be strings, not '%T'", w_name)
+    if not _isidentifier(w_name._value):
+        raise oefmt(space.w_TypeError, "__slots__ must be identifiers")
+    return w_name.identifier_w(space)
 
 def create_all_slots(w_self, hasoldstylebase, w_bestbase, force_new_layout):
     from pypy.objspace.std.listobject import StringSort
@@ -1073,13 +1081,12 @@
         wantdict = False
         wantweakref = False
         w_slots = dict_w['__slots__']
-        if (space.isinstance_w(w_slots, space.w_str) or
-            space.isinstance_w(w_slots, space.w_unicode)):
+        if space.isinstance_w(w_slots, space.w_text):
             slot_names_w = [w_slots]
         else:
             slot_names_w = space.unpackiterable(w_slots)
         for w_slot_name in slot_names_w:
-            slot_name = space.str_w(w_slot_name)
+            slot_name = slot_w(space, w_slot_name)
             if slot_name == '__dict__':
                 if wantdict or w_bestbase.hasdict:
                     raise oefmt(space.w_TypeError,
@@ -1124,8 +1131,6 @@
 
 def create_slot(w_self, slot_name, index_next_extra_slot):
     space = w_self.space
-    if not valid_slot_name(slot_name):
-        raise oefmt(space.w_TypeError, "__slots__ must be identifiers")
     # create member
     slot_name = mangle(slot_name, w_self.name)
     if slot_name not in w_self.dict_w:
@@ -1156,14 +1161,6 @@
                                  w_self.space.wrap(weakref_descr))
         w_self.weakrefable = True
 
-def valid_slot_name(slot_name):
-    if len(slot_name) == 0 or slot_name[0].isdigit():
-        return False
-    for c in slot_name:
-        if not c.isalnum() and c != '_':
-            return False
-    return True
-
 def setup_user_defined_type(w_self, force_new_layout):
     if len(w_self.bases_w) == 0:
         w_self.bases_w = [w_self.space.w_object]
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to