summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-02-08 17:17:58 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-02-08 17:17:58 (GMT)
commita2724095cd55d75497d9cd48d35911599f4dedda (patch)
tree3d140ea269727f28190631a02a1cd9c6b5219ec6 /Lib/test/test_grammar.py
parent51d8c526d5634fa1f0e4976fd357c5423a792082 (diff)
downloadcpython-a2724095cd55d75497d9cd48d35911599f4dedda.zip
cpython-a2724095cd55d75497d9cd48d35911599f4dedda.tar.gz
cpython-a2724095cd55d75497d9cd48d35911599f4dedda.tar.bz2
compiler now ignores constant statements
The compile ignores constant statements and emit a SyntaxWarning warning. Don't emit the warning for string statement because triple quoted string is a common syntax for multiline comments. Don't emit the warning on ellipis neither: 'def f(): ...' is a legit syntax for abstract functions. Changes: * test_ast: ignore SyntaxWarning when compiling test statements. Modify test_load_const() to use assignment expressions rather than constant expression. * test_code: add more kinds of constant statements, ignore SyntaxWarning when testing that the compiler removes constant statements. * test_grammar: ignore SyntaxWarning on the statement "1"
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r--Lib/test/test_grammar.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 8f8d71c..2d6f5ed 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -7,6 +7,7 @@ import unittest
import sys
# testing import *
from sys import *
+from test import support
class TokenTests(unittest.TestCase):
@@ -424,8 +425,11 @@ class GrammarTests(unittest.TestCase):
# Tested below
def test_expr_stmt(self):
+ msg = 'ignore constant statement'
+ with support.check_warnings((msg, SyntaxWarning)):
+ exec("1")
+
# (exprlist '=')* exprlist
- 1
1, 2, 3
x = 1
x = 1, 2, 3