[pypy-svn] r75077 - in pypy/branch/fast-forward/pypy/interpreter: pyparser test
benjamin at codespeak.net
benjamin at codespeak.net
Thu Jun 3 21:10:51 CEST 2010
Author: benjamin
Date: Thu Jun 3 21:10:31 2010
New Revision: 75077
Modified:
pypy/branch/fast-forward/pypy/interpreter/pyparser/pygram.py
pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py
pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py
Log:
the with statement is now always enabled
Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/pygram.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/pygram.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/pygram.py Thu Jun 3 21:10:31 2010
@@ -19,11 +19,6 @@
python_grammar = _get_python_grammar()
-python_grammar_no_with_statement = python_grammar.shared_copy()
-python_grammar_no_with_statement.keyword_ids = \
- python_grammar_no_with_statement.keyword_ids.copy()
-del python_grammar_no_with_statement.keyword_ids["with"]
-del python_grammar_no_with_statement.keyword_ids["as"]
class _Tokens(object):
pass
Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py Thu Jun 3 21:10:31 2010
@@ -129,15 +129,7 @@
flags = compile_info.flags
- # In order to not raise errors when 'as' or 'with' are used as names in
- # code that does not explicitly enable the with statement, we have two
- # grammars. One with 'as' and 'with' and keywords and one without.
- # This is far better than CPython, where the parser is hacked up to
- # check for __future__ imports and recognize new keywords accordingly.
- if flags & consts.CO_FUTURE_WITH_STATEMENT:
- self.grammar = pygram.python_grammar
- else:
- self.grammar = pygram.python_grammar_no_with_statement
+ self.grammar = pygram.python_grammar
# The tokenizer is very picky about how it wants its input.
source_lines = textsrc.splitlines(True)
Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py Thu Jun 3 21:10:31 2010
@@ -318,7 +318,7 @@
class AppTestWith:
def test_with_simple(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -340,7 +340,6 @@
def test_start_with_blank_line(self):
s = """
-from __future__ import with_statement
if 1:
class Context:
def __init__(self):
@@ -361,7 +360,6 @@
def test_raw_doc_string(self):
s = """r'doc'
-from __future__ import with_statement
class Context(object):
def __enter__(self):
global enter
@@ -377,7 +375,7 @@
def test_with_as_var(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -403,7 +401,7 @@
def test_with_raise_exception(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -438,7 +436,7 @@
def test_with_swallow_exception(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -469,7 +467,7 @@
def test_with_break(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -500,7 +498,7 @@
def test_with_continue(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -530,7 +528,7 @@
assert acontextfact.exit_params == (None, None, None)
def test_with_return(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
class Context:
def __init__(self):
@@ -558,20 +556,9 @@
assert acontextfact.calls == '__enter__ __body__ __exit__ __return__'.split()
assert acontextfact.exit_params == (None, None, None)
- def test_with_as_identifier(self):
- exec "with = 9"
-
def test_with_as_keyword(self):
try:
- exec "from __future__ import with_statement\nwith = 9"
- except SyntaxError:
- pass
- else:
- assert False, 'Assignment to with did not raise SyntaxError'
-
- def test_with_as_keyword_and_docstring(self):
- try:
- exec "'Docstring'\nfrom __future__ import with_statement\nwith = 9"
+ exec "with = 9"
except SyntaxError:
pass
else:
@@ -585,33 +572,11 @@
else:
assert False, 'Assignment to with did not raise SyntaxError'
- def test_with_as_keyword_multiple(self):
- try:
- exec "from __future__ import generators\nfrom __future__ import with_statement\nwith = 9"
- except SyntaxError:
- pass
- else:
- assert False, 'Assignment to with did not raise SyntaxError'
-
- def test_as_as_identifier(self):
- exec "as = 9"
- exec "import sys as foo"
-
- def test_as_as_keyword(self):
- try:
- exec "from __future__ import with_statement\nas = 9"
- except SyntaxError:
- pass
- else:
- assert False, 'Assignment to as did not raise SyntaxError'
-
- exec "from __future__ import with_statement\nimport sys as foo"
-
def test_missing_as_SyntaxError(self):
snippets = [
"import os.path a bar ",
"from os import path a bar",
- """from __future__ import with_statement
+ """
with foo a bar:
pass
"""]
@@ -625,7 +590,7 @@
def test_with_propagate_compileflag(self):
- s = """from __future__ import with_statement
+ s = """
if 1:
compile('''with x:
pass''', '', 'exec')
More information about the Pypy-commit
mailing list