[pypy-commit] pypy default: don't use deprecated 'new' module

rlamy noreply at buildbot.pypy.org
Sun Apr 27 19:05:05 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r71029:26d73c5f5c38
Date: 2014-04-27 18:04 +0100
http://bitbucket.org/pypy/pypy/changeset/26d73c5f5c38/

Log:	don't use deprecated 'new' module

diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -1,5 +1,5 @@
 from __future__ import with_statement
-import new
+import types
 import py
 from contextlib import contextmanager
 
@@ -943,7 +943,7 @@
 
     def monkey_patch_code(self, code, stacksize, flags, codestring, names, varnames):
         c = code
-        return new.code(c.co_argcount, c.co_nlocals, stacksize, flags,
+        return types.CodeType(c.co_argcount, c.co_nlocals, stacksize, flags,
                         codestring, c.co_consts, names, varnames,
                         c.co_filename, c.co_name, c.co_firstlineno,
                         c.co_lnotab)
@@ -964,7 +964,7 @@
             # this code is generated by pypy-c when compiling above f
             pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\xc9\x01\x00\xca\x00\x00S'
             new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
-            f2 = new.function(new_c, locals(), 'f')
+            f2 = types.FunctionType(new_c, locals(), 'f')
 
             graph = self.codetest(f2)
             all_ops = self.all_operations(graph)
@@ -984,7 +984,7 @@
             pypy_code = 'd\x01\x00\xcb\x00\x00D]\x0c\x00}\x00\x00|\x00\x00^\x02\x00q\x07\x00S'
             new_c = self.monkey_patch_code(f.func_code, 3, 67, pypy_code, (),
                                            ('i',))
-            f2 = new.function(new_c, locals(), 'f')
+            f2 = types.FunctionType(new_c, locals(), 'f')
 
             graph = self.codetest(f2)
             all_ops = self.all_operations(graph)
diff --git a/rpython/tool/sourcetools.py b/rpython/tool/sourcetools.py
--- a/rpython/tool/sourcetools.py
+++ b/rpython/tool/sourcetools.py
@@ -6,7 +6,7 @@
 # XXX We should try to generalize and single out one approach to dynamic
 # XXX code compilation.
 
-import sys, os, inspect, new
+import sys, os, inspect, types
 import py
 
 def render_docstr(func, indent_str='', closing_str=''):
@@ -127,7 +127,7 @@
     for name in names:
         if name not in kwargs:
             kwargs[name] = getattr(fromcode, name)
-    return new.code(
+    return types.CodeType(
              kwargs['co_argcount'],
              kwargs['co_nlocals'],
              kwargs['co_stacksize'],
@@ -218,9 +218,8 @@
     """Make a renamed copy of a function."""
     if globals is None:
         globals = func.func_globals
-    f = new.function(func.func_code, globals,
-                        newname, func.func_defaults,
-                        func.func_closure)
+    f = types.FunctionType(func.func_code, globals, newname,
+            func.func_defaults, func.func_closure)
     if func.func_dict:
         f.func_dict = {}
         f.func_dict.update(func.func_dict)


More information about the pypy-commit mailing list