Author: Ronan Lamy <[email protected]>
Branch: translation-cleanup
Changeset: r57446:d154897b2e07
Date: 2012-09-20 23:49 +0100
http://bitbucket.org/pypy/pypy/changeset/d154897b2e07/
Log: Raise FlowingError when attempting to write a global.
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -310,8 +310,8 @@
def setitem(self, w_obj, w_key, w_val):
# protect us from globals write access
if w_obj is self.frame.w_globals:
- raise SyntaxError("attempt to modify global attribute %r in %r"
- % (w_key, ec.graph.func))
+ raise FlowingError(self.frame,
+ "Attempting to modify global variable %r." % (w_key))
return self.do_operation_with_implicit_exceptions('setitem', w_obj,
w_key, w_val)
diff --git a/pypy/objspace/flow/test/test_objspace.py
b/pypy/objspace/flow/test/test_objspace.py
--- a/pypy/objspace/flow/test/test_objspace.py
+++ b/pypy/objspace/flow/test/test_objspace.py
@@ -460,6 +460,15 @@
def test_globalconstdict(self):
x = self.codetest(self.globalconstdict)
+ def test_dont_write_globals(self):
+ def f():
+ global DATA
+ DATA = 5
+ with py.test.raises(FlowingError) as excinfo:
+ self.codetest(f)
+ assert "modify global" in str(excinfo.value)
+ assert DATA == {'x':5, 'y':6}
+
#__________________________________________________________
def dictliteral(name):
x = {'x': 1}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit