mirror of
https://github.com/python/cpython.git
synced 2025-07-25 04:04:13 +00:00
Fix failure of test_compiler.py when compiling test_contextlib.py.
The culprit was an expression-less yield -- the first apparently in the standard library. I added a unit test for this. Also removed the hack to force compilation of test_with.py.
This commit is contained in:
parent
3a5468efb0
commit
5bde08dba3
2 changed files with 7 additions and 4 deletions
|
@ -408,11 +408,11 @@ class Transformer:
|
||||||
return Discard(expr, lineno=expr.lineno)
|
return Discard(expr, lineno=expr.lineno)
|
||||||
|
|
||||||
def yield_expr(self, nodelist):
|
def yield_expr(self, nodelist):
|
||||||
if len(nodelist)>1:
|
if len(nodelist) > 1:
|
||||||
value = nodelist[1]
|
value = self.com_node(nodelist[1])
|
||||||
else:
|
else:
|
||||||
value = Const(None)
|
value = Const(None)
|
||||||
return Yield(self.com_node(value), lineno=nodelist[0][2])
|
return Yield(value, lineno=nodelist[0][2])
|
||||||
|
|
||||||
def raise_stmt(self, nodelist):
|
def raise_stmt(self, nodelist):
|
||||||
# raise: [test [',' test [',' test]]]
|
# raise: [test [',' test [',' test]]]
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CompilerTest(unittest.TestCase):
|
||||||
for basename in os.listdir(dir):
|
for basename in os.listdir(dir):
|
||||||
if not basename.endswith(".py"):
|
if not basename.endswith(".py"):
|
||||||
continue
|
continue
|
||||||
if not TEST_ALL and random() < 0.98 and basename != "test_with.py":
|
if not TEST_ALL and random() < 0.98:
|
||||||
continue
|
continue
|
||||||
path = os.path.join(dir, basename)
|
path = os.path.join(dir, basename)
|
||||||
if test.test_support.verbose:
|
if test.test_support.verbose:
|
||||||
|
@ -43,6 +43,9 @@ class CompilerTest(unittest.TestCase):
|
||||||
def testNewClassSyntax(self):
|
def testNewClassSyntax(self):
|
||||||
compiler.compile("class foo():pass\n\n","<string>","exec")
|
compiler.compile("class foo():pass\n\n","<string>","exec")
|
||||||
|
|
||||||
|
def testYieldExpr(self):
|
||||||
|
compiler.compile("def g(): yield\n\n", "<string>", "exec")
|
||||||
|
|
||||||
def testLineNo(self):
|
def testLineNo(self):
|
||||||
# Test that all nodes except Module have a correct lineno attribute.
|
# Test that all nodes except Module have a correct lineno attribute.
|
||||||
filename = __file__
|
filename = __file__
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue