[pypy-commit] pypy py3k: kill the func_* attributes, in python3 we only have the corresponding __*__. Also, replace them in all the tests in interpreter/. There are probably other tests which will fail, I'll let buildbot to find them

antocuni noreply at buildbot.pypy.org
Tue Feb 21 10:50:52 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r52714:365afd942db2
Date: 2012-02-21 10:49 +0100
http://bitbucket.org/pypy/pypy/changeset/365afd942db2/

Log:	kill the func_* attributes, in python3 we only have the
	corresponding __*__. Also, replace them in all the tests in
	interpreter/. There are probably other tests which will fail, I'll
	let buildbot to find them

diff --git a/pypy/interpreter/test/test_appinterp.py b/pypy/interpreter/test/test_appinterp.py
--- a/pypy/interpreter/test/test_appinterp.py
+++ b/pypy/interpreter/test/test_appinterp.py
@@ -29,7 +29,7 @@
     app = appdef("""app(x,y): 
         return x + y
     """)
-    assert app.func_name == 'app'
+    assert app.__name__ == 'app'
     w_result = app(space, space.wrap(41), space.wrap(1))
     assert space.eq_w(w_result, space.wrap(42))
 
@@ -37,7 +37,7 @@
     app = appdef("""app(x,y=1): 
         return x + y
     """)
-    assert app.func_name == 'app'
+    assert app.__name__ == 'app'
     w_result = app(space, space.wrap(41)) 
     assert space.eq_w(w_result, space.wrap(42))
 
@@ -59,7 +59,7 @@
     app = appdef("""app(): 
         return 42 
     """)
-    assert app.func_name == 'app'
+    assert app.__name__ == 'app'
     w_result = app(space) 
     assert space.eq_w(w_result, space.wrap(42))
 
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
@@ -381,8 +381,8 @@
                (4 and
                   5):
                 def g(): "line 6"
-            fline = f.func_code.co_firstlineno
-            gline = g.func_code.co_firstlineno
+            fline = f.__code__.co_firstlineno
+            gline = g.__code__.co_firstlineno
         '''))
         code = self.compiler.compile(snippet, '<tmp>', 'exec', 0)
         space = self.space
@@ -400,7 +400,7 @@
             @foo       # line 4
             def f():   # line 5
                 pass   # line 6
-            fline = f.func_code.co_firstlineno
+            fline = f.__code__.co_firstlineno
         '''))
         code = self.compiler.compile(snippet, '<tmp>', 'exec', 0)
         space = self.space
@@ -766,7 +766,7 @@
 """
         ns = {}
         exec(source, ns)
-        code = ns['f'].func_code
+        code = ns['f'].__code__
         import dis, sys
         from io import StringIO
         s = StringIO()
@@ -873,7 +873,7 @@
             """
         ns = {}
         exec(source, ns)
-        code = ns['_f'].func_code
+        code = ns['_f'].__code__
 
         import sys, dis
         from io import StringIO
@@ -893,7 +893,7 @@
         """
         ns = {}
         exec(source, ns)
-        code = ns['_f'].func_code
+        code = ns['_f'].__code__
         
         import sys, dis
         from io import StringIO
diff --git a/pypy/interpreter/test/test_descrtypecheck.py b/pypy/interpreter/test/test_descrtypecheck.py
--- a/pypy/interpreter/test/test_descrtypecheck.py
+++ b/pypy/interpreter/test/test_descrtypecheck.py
@@ -5,11 +5,11 @@
     def test_getsetprop_get(self):
         def f():
             pass
-        getter =  type(f).__dict__['func_code'].__get__
+        getter =  type(f).__dict__['__code__'].__get__
         getter = getattr(getter, 'im_func', getter) # neutralizes pypy/cpython diff
         raises(TypeError, getter, 1, None)
 
     def test_func_code_get(self):
         def f():
             pass
-        raises(TypeError, type(f).func_code.__get__,1)
+        raises(TypeError, type(f).__code__.__get__,1)
diff --git a/pypy/interpreter/test/test_eval.py b/pypy/interpreter/test/test_eval.py
--- a/pypy/interpreter/test/test_eval.py
+++ b/pypy/interpreter/test/test_eval.py
@@ -7,7 +7,7 @@
     def setup_method(self, method):
         def c(x, y, *args):
             pass
-        code = PyCode._from_code(self.space, c.func_code)
+        code = PyCode._from_code(self.space, c.__code__)
 
         class ConcreteFastscopeFrame(Frame):
             
diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -682,5 +682,5 @@
         app_g = gateway.interp2app_temp(g)
         space = self.space
         w_g = space.wrap(app_g)
-        w_defs = space.getattr(w_g, space.wrap("func_defaults"))
+        w_defs = space.getattr(w_g, space.wrap("__defaults__"))
         assert space.is_w(w_defs, space.w_None)
diff --git a/pypy/interpreter/test/test_gateway.py b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -715,7 +715,7 @@
         class X(object):
             def __init__(self, **kw):
                 pass
-        clash = type.__call__.func_code.co_varnames[0]
+        clash = type.__call__.__code__.co_varnames[0]
 
         X(**{clash: 33})
         type.__call__(X, **{clash: 33})
@@ -724,28 +724,28 @@
         class X(object):
             def __init__(self, **kw):
                 pass
-        clash = object.__new__.func_code.co_varnames[0]
+        clash = object.__new__.__code__.co_varnames[0]
 
         X(**{clash: 33})
         object.__new__(X, **{clash: 33})
 
 
     def test_dict_new(self):
-        clash = dict.__new__.func_code.co_varnames[0]
+        clash = dict.__new__.__code__.co_varnames[0]
 
         dict(**{clash: 33})
         dict.__new__(dict, **{clash: 33})
 
     def test_dict_init(self):
         d = {}
-        clash = dict.__init__.func_code.co_varnames[0]
+        clash = dict.__init__.__code__.co_varnames[0]
 
         d.__init__(**{clash: 33})
         dict.__init__(d, **{clash: 33})
 
     def test_dict_update(self):
         d = {}
-        clash = dict.update.func_code.co_varnames[0]
+        clash = dict.update.__code__.co_varnames[0]
 
         d.update(**{clash: 33})
         dict.update(d, **{clash: 33})
diff --git a/pypy/interpreter/test/test_generator.py b/pypy/interpreter/test/test_generator.py
--- a/pypy/interpreter/test/test_generator.py
+++ b/pypy/interpreter/test/test_generator.py
@@ -17,7 +17,7 @@
             yield 1
             assert g.gi_running
         g = f()
-        assert g.gi_code is f.func_code
+        assert g.gi_code is f.__code__
         assert g.__name__ == 'f'
         assert g.gi_frame is not None
         assert not g.gi_running
@@ -26,7 +26,7 @@
         raises(StopIteration, next, g)
         assert not g.gi_running
         assert g.gi_frame is None
-        assert g.gi_code is f.func_code
+        assert g.gi_code is f.__code__
         assert g.__name__ == 'f'
 
     def test_generator3(self):
diff --git a/pypy/interpreter/test/test_nestedscope.py b/pypy/interpreter/test/test_nestedscope.py
--- a/pypy/interpreter/test/test_nestedscope.py
+++ b/pypy/interpreter/test/test_nestedscope.py
@@ -66,7 +66,7 @@
             return f
 
         g = f(10)
-        assert g.func_closure[0].cell_contents == 10
+        assert g.__closure__[0].cell_contents == 10
 
     def test_empty_cell_contents(self):
 
@@ -77,7 +77,7 @@
             x = 1
 
         g = f()
-        raises(ValueError, "g.func_closure[0].cell_contents")
+        raises(ValueError, "g.__closure__[0].cell_contents")
 
     def test_compare_cells(self):
         def f(n):
@@ -87,8 +87,8 @@
                   return x + y
             return f
 
-        g0 = f(0).func_closure[0]
-        g1 = f(1).func_closure[0]
+        g0 = f(0).__closure__[0]
+        g1 = f(1).__closure__[0]
         assert cmp(g0, g1) == -1
 
     def test_leaking_class_locals(self):
diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py
--- a/pypy/interpreter/test/test_pyframe.py
+++ b/pypy/interpreter/test/test_pyframe.py
@@ -36,7 +36,7 @@
             import sys
             f = sys._getframe()
             return f.f_code
-        assert g() is g.func_code
+        assert g() is g.__code__
 
     def test_f_trace_del(self): 
         import sys
@@ -52,7 +52,7 @@
             y = f.f_lineno
             z = f.f_lineno
             return [x, y, z]
-        origin = g.func_code.co_firstlineno
+        origin = g.__code__.co_firstlineno
         assert g() == [origin+3, origin+4, origin+5]
 
     def test_f_lineno_set(self):
@@ -457,7 +457,7 @@
         len(seen)     # take one line
         del f.f_trace
         len(seen)     # take one line
-        firstline = set_the_trace.func_code.co_firstlineno
+        firstline = set_the_trace.__code__.co_firstlineno
         assert seen == [(1, f, firstline + 6, 'line', None),
                         (1, f, firstline + 7, 'line', None),
                         (1, f, firstline + 8, 'line', None)]
diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -22,7 +22,7 @@
         if not hasattr(len, 'func_code'):
             skip("Cannot run this test if builtins have no func_code")
         import inspect
-        args, varargs, varkw = inspect.getargs(len.func_code)
+        args, varargs, varkw = inspect.getargs(len.__code__)
         assert args == ['obj']
         assert varargs is None
         assert varkw is None
@@ -84,7 +84,7 @@
         def f():
             return 42
         import pickle
-        code = f.func_code
+        code = f.__code__
         pckl = pickle.dumps(code)
         result = pickle.loads(pckl)
         assert code == result
@@ -131,13 +131,13 @@
         import pickle
         pckl   = pickle.dumps(func)
         result = pickle.loads(pckl)
-        assert func.func_name     == result.func_name
-        assert func.func_closure  == result.func_closure
-        assert func.func_code     == result.func_code
-        assert func.func_defaults == result.func_defaults
-        assert func.func_dict     == result.func_dict
-        assert func.func_doc      == result.func_doc
-        assert func.func_globals  == result.func_globals
+        assert func.__name__     == result.__name__
+        assert func.__closure__  == result.__closure__
+        assert func.__code__     == result.__code__
+        assert func.__defaults__ == result.__defaults__
+        assert func.__dict__     == result.__dict__
+        assert func.__doc__      == result.__doc__
+        assert func.__globals__  == result.__globals__
     
     def test_pickle_cell(self):
         def g():
@@ -145,7 +145,7 @@
             def f():
                 x[0] += 1
                 return x
-            return f.func_closure[0]
+            return f.__closure__[0]
         import pickle
         cell = g()
         pckl = pickle.dumps(cell)
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -772,19 +772,13 @@
     __repr__ = interp2app(Function.descr_function_repr, descrmismatch='__repr__'),
     __reduce__ = interp2app(Function.descr_function__reduce__),
     __setstate__ = interp2app(Function.descr_function__setstate__),
-    func_code = getset_func_code,
-    func_doc = getset_func_doc,
-    func_name = getset_func_name,
-    func_dict = getset_func_dict,
-    func_defaults = getset_func_defaults,
-    func_globals = interp_attrproperty_w('w_func_globals', cls=Function),
-    func_closure = GetSetProperty( Function.fget_func_closure ),
     __code__ = getset_func_code,
     __doc__ = getset_func_doc,
     __name__ = getset_func_name,
     __dict__ = getset_func_dict,
     __defaults__ = getset_func_defaults,
     __globals__ = interp_attrproperty_w('w_func_globals', cls=Function),
+    __closure__ = GetSetProperty( Function.fget_func_closure ),
     __module__ = getset___module__,
     __weakref__ = make_weakref_descr(Function),
     )


More information about the pypy-commit mailing list