Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r90436:205b129940e0
Date: 2017-03-01 11:42 +0000
http://bitbucket.org/pypy/pypy/changeset/205b129940e0/
Log: Merged in robert-zaremba/pypy/fix-global (pull request #525)
Fixed bug translating SyntaxWarning to SyntaxError
diff --git a/pypy/interpreter/astcompiler/misc.py
b/pypy/interpreter/astcompiler/misc.py
--- a/pypy/interpreter/astcompiler/misc.py
+++ b/pypy/interpreter/astcompiler/misc.py
@@ -9,7 +9,7 @@
try:
warnings.warn_explicit(msg, SyntaxWarning, fn, lineno)
except SyntaxWarning:
- raise SyntaxError(msg, fn, lineno, offset)
+ raise SyntaxError(msg, (fn, lineno, offset, msg))
""", filename=__file__)
_emit_syntax_warning = app.interphook("syntax_warning")
del app
diff --git a/pypy/interpreter/astcompiler/test/test_misc.py
b/pypy/interpreter/astcompiler/test/test_misc.py
--- a/pypy/interpreter/astcompiler/test/test_misc.py
+++ b/pypy/interpreter/astcompiler/test/test_misc.py
@@ -12,3 +12,23 @@
assert mangle("__foo", "__Bar") == "_Bar__foo"
assert mangle("__foo", "___") == "__foo"
assert mangle("___foo", "__Bar") == "_Bar___foo"
+
+def app_test_warning_to_error_translation():
+ import warnings
+
+ with warnings.catch_warnings():
+ warnings.filterwarnings("error", module="<test string>")
+ statement = """\
+def wrong1():
+ a = 1
+ b = 2
+ global a
+ global b
+"""
+ try:
+ compile(statement, '<test string>', 'exec')
+ except SyntaxError as err:
+ assert err.lineno is not None
+ assert err.filename is not None
+ assert err.offset is not None
+ assert err.message is not None
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit