[pypy-svn] r66242 - pypy/branch/parser-compiler/pypy/interpreter/astcompiler

benjamin at codespeak.net benjamin at codespeak.net
Wed Jul 15 19:35:44 CEST 2009


Author: benjamin
Date: Wed Jul 15 19:35:43 2009
New Revision: 66242

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
Log:
implment a utility for syntax warnings

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py	Wed Jul 15 19:35:43 2009
@@ -1,5 +1,26 @@
+from pypy.interpreter import gateway
 from pypy.interpreter.astcompiler import ast
 
+
+app = gateway.applevel("""
+def syntax_warning(msg, fn, lineno, offset):
+    import warnings
+    try:
+        warnings.warn_explicit(msg, SyntaxWarning, fn, lineno)
+    except SyntaxWarning:
+        raise SyntaxError(msg, fn, lineno, offset)
+""", filename=__file__)
+_emit_syntax_warning = app.interphook("syntax_warning")
+del app
+
+def syntax_warning(space, msg, fn, lineno, offset):
+    w_msg = space.wrap(msg)
+    w_filename = space.wrap(fn)
+    w_lineno = space.wrap(lineno)
+    w_offset = space.wrap(offset)
+    _emit_syntax_warning(space, w_msg, w_filename, w_lineno, w_offset)
+
+
 def flatten(tup):
     elts = []
     for elt in tup:



More information about the Pypy-commit mailing list