Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r58353:22744399aa71
Date: 2012-10-22 08:31 +0200
http://bitbucket.org/pypy/pypy/changeset/22744399aa71/

Log:    Implement "Barry as BDFL" compile flag. It's not only a joke: this
        is how <> is now disallowed in normal Python3 code.

diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -853,6 +853,11 @@
             elif comp_type == tokens.GREATEREQUAL:
                 return ast.GtE
             elif comp_type == tokens.NOTEQUAL:
+                flufl = self.compile_info.flags & 
consts.CO_FUTURE_BARRY_AS_BDFL
+                if flufl and comp_node.value == '!=':
+                    self.error('message', comp_node)
+                elif not flufl and comp_node.value == '<>':
+                    self.error('message', comp_node)
                 return ast.NotEq
             elif comp_type == tokens.NAME:
                 if comp_node.value == "is":
@@ -1118,7 +1123,6 @@
         elif first_child_type == tokens.STRING:
             space = self.space
             encoding = self.compile_info.encoding
-            flags = self.compile_info.flags
             try:
                 sub_strings_w = [parsestring.parsestr(space, encoding, s.value)
                                  for s in atom_node.children]
diff --git a/pypy/interpreter/astcompiler/consts.py 
b/pypy/interpreter/astcompiler/consts.py
--- a/pypy/interpreter/astcompiler/consts.py
+++ b/pypy/interpreter/astcompiler/consts.py
@@ -15,6 +15,7 @@
 CO_FUTURE_WITH_STATEMENT = 0x8000
 CO_FUTURE_PRINT_FUNCTION = 0x10000
 CO_FUTURE_UNICODE_LITERALS = 0x20000
+CO_FUTURE_BARRY_AS_BDFL = 0x40000
 CO_CONTAINSGLOBALS = 0x80000 # pypy-specific: need to check that it's not used
                              # by any other flag
 
diff --git a/pypy/interpreter/pycompiler.py b/pypy/interpreter/pycompiler.py
--- a/pypy/interpreter/pycompiler.py
+++ b/pypy/interpreter/pycompiler.py
@@ -101,7 +101,7 @@
     """
     def __init__(self, space, override_version=None):
         PyCodeCompiler.__init__(self, space)
-        self.future_flags = future.futureFlags_2_7
+        self.future_flags = future.futureFlags_3_2
         self.parser = pyparse.PythonParser(space, self.future_flags)
         self.additional_rules = {}
         self.compiler_flags = self.future_flags.allowed_flags
diff --git a/pypy/interpreter/pyparser/future.py 
b/pypy/interpreter/pyparser/future.py
--- a/pypy/interpreter/pyparser/future.py
+++ b/pypy/interpreter/pyparser/future.py
@@ -24,8 +24,9 @@
 the "in" comparisons with explicit numeric comparisons.
 """
 
-from pypy.interpreter.astcompiler.consts import CO_GENERATOR_ALLOWED, \
-    CO_FUTURE_DIVISION, CO_FUTURE_WITH_STATEMENT, CO_FUTURE_ABSOLUTE_IMPORT
+from pypy.interpreter.astcompiler.consts import (
+    CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION, CO_FUTURE_WITH_STATEMENT,
+    CO_FUTURE_ABSOLUTE_IMPORT, CO_FUTURE_BARRY_AS_BDFL)
 
 def get_futures(future_flags, source):
     futures = FutureAutomaton(future_flags, source)
diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -778,6 +778,22 @@
         for case in cases:
             raises(SyntaxError, compile, case, "<test>", "exec")
 
+    def test_barry_as_bdfl(self):
+        # from test_flufl.py :-)
+        import __future__
+        code = "from __future__ import barry_as_FLUFL; 2 {0} 3"
+        compile(code.format('<>'), '<BDFL test>', 'exec',
+                __future__.CO_FUTURE_BARRY_AS_BDFL)
+        raises(SyntaxError, compile, code.format('!='),
+               '<FLUFL test>', 'exec',
+               __future__.CO_FUTURE_BARRY_AS_BDFL)
+
+    def test_guido_as_bdfl(self):
+        # from test_flufl.py :-)
+        code = '2 {0} 3'
+        compile(code.format('!='), '<BDFL test>', 'exec')
+        raises(SyntaxError, compile, code.format('<>'),
+               '<FLUFL test>', 'exec')
 
 
 class AppTestOptimizer:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to