[pypy-commit] pypy py3k: merge heads
antocuni
noreply at buildbot.pypy.org
Tue Feb 21 16:07:41 CET 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r52737:4224a1520aa4
Date: 2012-02-21 16:06 +0100
http://bitbucket.org/pypy/pypy/changeset/4224a1520aa4/
Log: merge heads
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -528,7 +528,7 @@
else: # line 5
if 1: pass # line 6
import dis
- co = ireturn_example.func_code
+ co = ireturn_example.__code__
linestarts = list(dis.findlinestarts(co))
addrreturn = linestarts[-1][0]
x = [addrreturn == (len(co.co_code) - 4)]
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_typedef.py b/pypy/interpreter/test/test_typedef.py
--- a/pypy/interpreter/test/test_typedef.py
+++ b/pypy/interpreter/test/test_typedef.py
@@ -313,20 +313,22 @@
cls.w_path = cls.space.wrap(str(path))
def test_destructor(self):
- import gc, os
+ import gc, array
seen = []
- class MyFile(file):
+ class MyArray(array.array):
def __del__(self):
+ # here we check that we can still access the array, i.e. that
+ # the interp-level __del__ has not been called yet
seen.append(10)
- seen.append(os.lseek(self.fileno(), 2, 0))
- f = MyFile(self.path, 'r')
- fd = f.fileno()
- seen.append(os.lseek(fd, 5, 0))
- del f
+ seen.append(self[0])
+ a = MyArray('i')
+ a.append(42)
+ seen.append(a[0])
+ del a
gc.collect(); gc.collect(); gc.collect()
lst = seen[:]
- assert lst == [5, 10, 2]
- raises(OSError, os.lseek, fd, 7, 0)
+ print(lst)
+ assert lst == [42, 10, 42]
def test_method_attrs(self):
import sys
diff --git a/pypy/interpreter/test/test_zpy.py b/pypy/interpreter/test/test_zpy.py
--- a/pypy/interpreter/test/test_zpy.py
+++ b/pypy/interpreter/test/test_zpy.py
@@ -11,6 +11,12 @@
argslist = map(str, args)
popen = subprocess.Popen(argslist, stdout=subprocess.PIPE)
stdout, stderr = popen.communicate()
+ print '--- stdout ---'
+ print stdout
+ print
+ print '--- stderr ---'
+ print stderr
+ print
return stdout
@@ -18,19 +24,19 @@
"""Ensures sys.executable points to the py.py script"""
# TODO : watch out for spaces/special chars in pypypath
output = run(sys.executable, pypypath,
- "-c", "import sys;print sys.executable")
+ "-c", "import sys;print(sys.executable)")
assert output.splitlines()[-1] == pypypath
def test_special_names():
"""Test the __name__ and __file__ special global names"""
- cmd = "print __name__; print '__file__' in globals()"
+ cmd = "print(__name__); print('__file__' in globals())"
output = run(sys.executable, pypypath, '-c', cmd)
assert output.splitlines()[-2] == '__main__'
assert output.splitlines()[-1] == 'False'
tmpfilepath = str(udir.join("test_py_script_1.py"))
tmpfile = file( tmpfilepath, "w" )
- tmpfile.write("print __name__; print __file__\n")
+ tmpfile.write("print(__name__); print(__file__)\n")
tmpfile.close()
output = run(sys.executable, pypypath, tmpfilepath)
@@ -41,22 +47,22 @@
"""Some tests on argv"""
# test 1 : no arguments
output = run(sys.executable, pypypath,
- "-c", "import sys;print sys.argv")
+ "-c", "import sys;print(sys.argv)")
assert output.splitlines()[-1] == str(['-c'])
# test 2 : some arguments after
output = run(sys.executable, pypypath,
- "-c", "import sys;print sys.argv", "hello")
+ "-c", "import sys;print(sys.argv)", "hello")
assert output.splitlines()[-1] == str(['-c','hello'])
# test 3 : additionnal pypy parameters
output = run(sys.executable, pypypath,
- "-O", "-c", "import sys;print sys.argv", "hello")
+ "-O", "-c", "import sys;print(sys.argv)", "hello")
assert output.splitlines()[-1] == str(['-c','hello'])
SCRIPT_1 = """
import sys
-print sys.argv
+print(sys.argv)
"""
def test_scripts():
tmpfilepath = str(udir.join("test_py_script.py"))
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),
)
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
@@ -259,10 +259,10 @@
assert ff.__get__(0, int)(42) == (int, 42)
assert ff.__get__(0)(42) == (int, 42)
- assert C.goo.im_self is C
- assert D.goo.im_self is D
- assert super(D,D).goo.im_self is D
- assert super(D,d).goo.im_self is D
+ assert C.goo.__self__ is C
+ assert D.goo.__self__ is D
+ assert super(D,D).goo.__self__ is D
+ assert super(D,d).goo.__self__ is D
assert super(D,D).goo() == (D,)
assert super(D,d).goo() == (D,)
diff --git a/pypy/module/_collections/app_defaultdict.py b/pypy/module/_collections/app_defaultdict.py
--- a/pypy/module/_collections/app_defaultdict.py
+++ b/pypy/module/_collections/app_defaultdict.py
@@ -25,7 +25,7 @@
def __missing__(self, key):
pass # this method is written at interp-level
- __missing__.func_code = _collections.__missing__.func_code
+ __missing__.__code__ = _collections.__missing__.__code__
def __repr__(self, recurse=set()):
# XXX not thread-safe, but good enough
diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -7,20 +7,20 @@
def test_basics(self):
from _collections import deque
- d = deque(xrange(-5125, -5000))
- d.__init__(xrange(200))
- for i in xrange(200, 400):
+ d = deque(range(-5125, -5000))
+ d.__init__(range(200))
+ for i in range(200, 400):
d.append(i)
- for i in reversed(xrange(-200, 0)):
+ for i in reversed(range(-200, 0)):
d.appendleft(i)
assert list(d) == range(-200, 400)
assert len(d) == 600
- left = [d.popleft() for i in xrange(250)]
+ left = [d.popleft() for i in range(250)]
assert left == range(-200, 50)
assert list(d) == range(50, 400)
- right = [d.pop() for i in xrange(250)]
+ right = [d.pop() for i in range(250)]
right.reverse()
assert right == range(150, 400)
assert list(d) == range(50, 150)
@@ -139,9 +139,9 @@
def test_getitem(self):
from _collections import deque
n = 200
- l = xrange(1000, 1000 + n)
+ l = range(1000, 1000 + n)
d = deque(l)
- for j in xrange(-n, n):
+ for j in range(-n, n):
assert d[j] == l[j]
raises(IndexError, "d[-n-1]")
raises(IndexError, "d[n]")
@@ -149,12 +149,12 @@
def test_setitem(self):
from _collections import deque
n = 200
- d = deque(xrange(n))
- for i in xrange(n):
+ d = deque(range(n))
+ for i in range(n):
d[i] = 10 * i
- assert list(d) == [10*i for i in xrange(n)]
+ assert list(d) == [10*i for i in range(n)]
l = list(d)
- for i in xrange(1-n, 0, -3):
+ for i in range(1-n, 0, -3):
d[i] = 7*i
l[i] = 7*i
assert list(d) == l
@@ -167,7 +167,7 @@
def test_reverse(self):
from _collections import deque
- d = deque(xrange(1000, 1200))
+ d = deque(range(1000, 1200))
d.reverse()
assert list(d) == list(reversed(range(1000, 1200)))
#
@@ -232,7 +232,7 @@
def test_repr(self):
from _collections import deque
- d = deque(xrange(20))
+ d = deque(range(20))
e = eval(repr(d))
assert d == e
d.append(d)
@@ -244,7 +244,7 @@
def test_roundtrip_iter_init(self):
from _collections import deque
- d = deque(xrange(200))
+ d = deque(range(200))
e = deque(d)
assert d is not e
assert d == e
@@ -288,7 +288,7 @@
def test_reversed(self):
from _collections import deque
- for s in ('abcd', xrange(200)):
+ for s in ('abcd', range(200)):
assert list(reversed(deque(s))) == list(reversed(s))
def test_free(self):
diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py
--- a/pypy/module/_continuation/interp_continuation.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -172,7 +172,7 @@
raise TypeError(
"can\'t send non-None value to a just-started continulet")
return func(c, *args, **kwds)
- return start.func_code
+ return start.__code__
''')
self.entrypoint_pycode = space.interp_w(PyCode, w_code)
self.entrypoint_pycode.hidden_applevel = True
diff --git a/pypy/module/_lsprof/test/test_cprofile.py b/pypy/module/_lsprof/test/test_cprofile.py
--- a/pypy/module/_lsprof/test/test_cprofile.py
+++ b/pypy/module/_lsprof/test/test_cprofile.py
@@ -107,8 +107,8 @@
entries = {}
for entry in stats:
entries[entry.code] = entry
- efoo = entries[foo.func_code]
- ebar = entries[bar.func_code]
+ efoo = entries[foo.__code__]
+ ebar = entries[bar.__code__]
assert 0.9 < efoo.totaltime < 2.9
# --- cannot test .inlinetime, because it does not include
# --- the time spent doing the call to time.time()
diff --git a/pypy/module/pypyjit/test/test_jit_hook.py b/pypy/module/pypyjit/test/test_jit_hook.py
--- a/pypy/module/pypyjit/test/test_jit_hook.py
+++ b/pypy/module/pypyjit/test/test_jit_hook.py
@@ -120,8 +120,8 @@
int_add = elem[3][0]
dmp = elem[3][1]
assert isinstance(dmp, pypyjit.DebugMergePoint)
- assert dmp.pycode is self.f.func_code
- assert dmp.greenkey == (self.f.func_code, 0, False)
+ assert dmp.pycode is self.f.__code__
+ assert dmp.greenkey == (self.f.__code__, 0, False)
assert dmp.call_depth == 0
assert int_add.name == 'int_add'
assert int_add.num == self.int_add_num
@@ -132,13 +132,14 @@
assert len(all) == 2
def test_on_compile_exception(self):
- import pypyjit, sys, cStringIO
+ import pypyjit, sys
+ from io import StringIO
def hook(*args):
1/0
pypyjit.set_compile_hook(hook)
- s = cStringIO.StringIO()
+ s = StringIO()
prev = sys.stderr
sys.stderr = s
try:
@@ -224,9 +225,9 @@
def f():
pass
- op = DebugMergePoint([Box(0)], 'repr', 'pypyjit', 2, (f.func_code, 0, 0))
+ op = DebugMergePoint([Box(0)], 'repr', 'pypyjit', 2, (f.__code__, 0, 0))
assert op.bytecode_no == 0
- assert op.pycode is f.func_code
+ assert op.pycode is f.__code__
assert repr(op) == 'repr'
assert op.jitdriver_name == 'pypyjit'
assert op.num == self.dmp_num
diff --git a/pypy/module/test_lib_pypy/test_greenlet.py b/pypy/module/test_lib_pypy/test_greenlet.py
--- a/pypy/module/test_lib_pypy/test_greenlet.py
+++ b/pypy/module/test_lib_pypy/test_greenlet.py
@@ -18,7 +18,7 @@
lst.append(2)
g.switch()
lst.append(4)
- assert lst == range(5)
+ assert lst == list(range(5))
def test_parent(self):
from greenlet import greenlet
diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -655,7 +655,7 @@
"objspace.opcodes.CALL_METHOD": True})
#
def check(space, w_func, name):
- w_code = space.getattr(w_func, space.wrap('func_code'))
+ w_code = space.getattr(w_func, space.wrap('__code__'))
nameindex = map(space.str_w, w_code.co_names_w).index(name)
entry = w_code._mapdict_caches[nameindex]
entry.failure_counter = 0
diff --git a/pypy/objspace/std/test/test_proxy_function.py b/pypy/objspace/std/test/test_proxy_function.py
--- a/pypy/objspace/std/test/test_proxy_function.py
+++ b/pypy/objspace/std/test/test_proxy_function.py
@@ -68,7 +68,7 @@
pass
fun = self.get_proxy(f)
- assert fun.func_code is f.func_code
+ assert fun.__code__ is f.__code__
def test_funct_prop_setter_del(self):
def f():
More information about the pypy-commit
mailing list