Author: Ronan Lamy <[email protected]>
Branch: py3.7
Changeset: r97347:a676a5366a60
Date: 2019-08-31 01:55 +0100
http://bitbucket.org/pypy/pypy/changeset/a676a5366a60/
Log: hg merge py3.6
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -14,7 +14,6 @@
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
CO_GENERATOR, CO_COROUTINE, CO_KILL_DOCSTRING, CO_YIELD_INSIDE_TRY,
CO_ITERABLE_COROUTINE, CO_ASYNC_GENERATOR)
-from pypy.tool import dis3
from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.objectmodel import compute_hash, we_are_translated
@@ -307,6 +306,7 @@
def dump(self):
"""NOT_RPYTHON: A dis.dis() dump of the code object."""
+ from pypy.tool import dis3
if not hasattr(self, 'co_consts'):
self.co_consts = [w if isinstance(w, PyCode) else
self.space.unwrap(w)
for w in self.co_consts_w]
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -69,7 +69,7 @@
f_generator_nowref = None # (only one of the two attrs)
last_instr = -1
f_backref = jit.vref_None
-
+
escaped = False # see mark_as_escaped()
debugdata = None
@@ -79,7 +79,7 @@
lastblock = None
# other fields:
-
+
# builtin - builtin cache, only if honor__builtins__ is True
# defaults to False
diff --git a/pypy/interpreter/test/apptest_pyframe.py
b/pypy/interpreter/test/apptest_pyframe.py
--- a/pypy/interpreter/test/apptest_pyframe.py
+++ b/pypy/interpreter/test/apptest_pyframe.py
@@ -61,6 +61,34 @@
print(repr(g.__code__.co_lnotab))
assert g() == [origin+3, origin+5+127, origin+7+127+1000]
+class JumpTracer:
+ """Defines a trace function that jumps from one place to another."""
+
+ def __init__(self, function, jumpFrom, jumpTo, event='line',
+ decorated=False):
+ self.code = function.__code__
+ self.jumpFrom = jumpFrom
+ self.jumpTo = jumpTo
+ self.event = event
+ self.firstLine = None if decorated else self.code.co_firstlineno
+ self.done = False
+
+ def trace(self, frame, event, arg):
+ if self.done:
+ return
+ # frame.f_code.co_firstlineno is the first line of the decorator when
+ # 'function' is decorated and the decorator may be written using
+ # multiple physical lines when it is too long. Use the first line
+ # trace event in 'function' to find the first line of 'function'.
+ if (self.firstLine is None and frame.f_code == self.code and
+ event == 'line'):
+ self.firstLine = frame.f_lineno - 1
+ if (event == self.event and self.firstLine and
+ frame.f_lineno == self.firstLine + self.jumpFrom):
+ frame.f_lineno = self.firstLine + self.jumpTo
+ self.done = True
+ return self.trace
+
def test_f_lineno_set(tempfile):
def tracer(f, *args):
def y(f, *args):
@@ -87,7 +115,7 @@
sys.settrace(None)
# assert did not crash
-def test_f_lineno_set_2(tempfile):
+def test_f_lineno_set_2():
counter = [0]
errors = []
@@ -101,10 +129,6 @@
errors.append(e)
return tracer
- # obscure: call open beforehand, py3k's open invokes some app
- # level code that confuses our tracing (likely due to the
- # testing env, otherwise it's not a problem)
- f = open(tempfile, 'w')
def function():
try:
raise ValueError
@@ -133,18 +157,39 @@
output.append(8)
output.append(9)
output = []
-
- def tracer(f, event, *args):
- if event == 'line' and len(output) == 1:
- f.f_lineno += 5
- return tracer
+ tracer = JumpTracer(jump_in_nested_finally, 4, 9)
import sys
- sys.settrace(tracer)
+ sys.settrace(tracer.trace)
jump_in_nested_finally(output)
sys.settrace(None)
assert output == [2, 9]
+def test_f_lineno_set_4():
+ pytest.skip("test is failing on pypy")
+ def jump_in_nested_finally(output):
+ try:
+ output.append(2)
+ 1/0
+ return
+ finally:
+ output.append(6)
+ output.append(7)
+ output.append(8)
+ output = []
+ tracer = JumpTracer(jump_in_nested_finally, 6, 7)
+
+ import sys
+ sys.settrace(tracer.trace)
+ try:
+ jump_in_nested_finally(output)
+ except ZeroDivisionError:
+ sys.settrace(None)
+ else:
+ sys.settrace(None)
+ assert False, 'did not raise'
+ assert output == [2, 7]
+
def test_f_lineno_set_firstline():
seen = []
def tracer(f, event, *args):
diff --git a/pypy/module/__builtin__/compiling.py
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -130,6 +130,16 @@
keywords=keywords,
keywords_w=kwds_w.values())
w_namespace = space.call_args(w_prep, args)
+ if not space.ismapping_w(w_namespace):
+ if isclass:
+ raise oefmt(space.w_TypeError,
+ "%N.__prepare__ must return a mapping, not %T",
+ w_meta, w_namespace)
+ else:
+ raise oefmt(space.w_TypeError,
+ "<metaclass>.__prepare__ must return a mapping, not %T",
+ w_namespace)
+
code = w_func.getcode()
frame = space.createframe(code, w_func.w_func_globals, w_func)
frame.setdictscope(w_namespace)
diff --git a/pypy/module/posix/interp_nt.py b/pypy/module/posix/interp_nt.py
--- a/pypy/module/posix/interp_nt.py
+++ b/pypy/module/posix/interp_nt.py
@@ -35,7 +35,7 @@
# plain NotImplementedError is invalid RPython
-class LLNotImplemented(NotImplementedError):
+class LLNotImplemented(Exception):
def __init__(self, msg):
self.msg = msg
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
@@ -1277,6 +1277,23 @@
assert C.foo == 42
"""
+ def test_prepare_error(self):
+ """
+ class BadMeta:
+ @classmethod
+ def __prepare__(cls, *args, **kwargs):
+ return 42
+ def make_class(meta):
+ class Foo(metaclass=meta):
+ pass
+ excinfo = raises(TypeError, make_class, BadMeta)
+ print(excinfo.value.args[0])
+ assert excinfo.value.args[0].startswith('BadMeta.__prepare__')
+ # Non-type as metaclass
+ excinfo = raises(TypeError, make_class, BadMeta())
+ assert excinfo.value.args[0].startswith('<metaclass>.__prepare__')
+ """
+
def test_crash_mro_without_object_1(self):
"""
class X(type):
diff --git a/rpython/rlib/rsiphash.py b/rpython/rlib/rsiphash.py
--- a/rpython/rlib/rsiphash.py
+++ b/rpython/rlib/rsiphash.py
@@ -170,10 +170,12 @@
# unicode strings where CPython uses 2 bytes per character.
addr = rstr._get_raw_buf_unicode(rstr.UNICODE, ll_s, 0)
SZ = rffi.sizeof(rstr.UNICODE.chars.OF)
- for i in range(length):
+ i = 0
+ while i < length:
if ord(ll_s.chars[i]) > 0xFF:
length *= SZ
break
+ i += 1
else:
x = _siphash24(addr, length, SZ)
keepalive_until_here(ll_s)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit