[pypy-commit] pypy assert-rewrite: Better error reporting when seeing locals()
rlamy
pypy.commits at gmail.com
Sun Nov 27 15:15:54 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: assert-rewrite
Changeset: r88684:7f27f353a8f6
Date: 2016-11-27 20:14 +0000
http://bitbucket.org/pypy/pypy/changeset/7f27f353a8f6/
Log: Better error reporting when seeing locals()
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -32,13 +32,12 @@
@register_flow_sc(locals)
def sc_locals(_, *args):
- raise Exception(
- "A function calling locals() is not RPython. "
- "Note that if you're translating code outside the PyPy "
- "repository, a likely cause is that py.test's --assert=rewrite "
- "mode is getting in the way. You should copy the file "
- "pytest.ini from the root of the PyPy repository into your "
- "own project.")
+ from rpython.flowspace.flowcontext import FlowingError
+ raise FlowingError(
+ "A function calling locals() is not RPython. A likely cause is that "
+ "py.test's assert rewriting is getting in the way. If so, you "
+ "should use `rpython.rlib.objectmodel.assert_()` instead of an "
+ "assert statement here.")
@register_flow_sc(getattr)
def sc_getattr(ctx, w_obj, w_index, w_default=None):
diff --git a/rpython/translator/c/test/test_genc.py b/rpython/translator/c/test/test_genc.py
--- a/rpython/translator/c/test/test_genc.py
+++ b/rpython/translator/c/test/test_genc.py
@@ -8,7 +8,7 @@
from rpython.rlib.entrypoint import entrypoint_highlevel
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint, intmask
-from rpython.rlib.objectmodel import specialize
+from rpython.rlib.objectmodel import specialize, assert_
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.lltype import *
from rpython.rtyper.lltypesystem.rstr import STR
@@ -78,7 +78,7 @@
if a == 'True':
args += (True,)
else:
- assert a == 'False'
+ assert_(a == 'False')
args += (False,)
elif argtype is float:
if a == 'inf':
More information about the pypy-commit
mailing list