Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bde08d

Browse files
committed
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.
1 parent 3a5468e commit 5bde08d

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

Lib/compiler/transformer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ def yield_stmt(self, nodelist):
408408
return Discard(expr, lineno=expr.lineno)
409409

410410
def yield_expr(self, nodelist):
411-
if len(nodelist)>1:
412-
value = nodelist[1]
411+
if len(nodelist) > 1:
412+
value = self.com_node(nodelist[1])
413413
else:
414414
value = Const(None)
415-
return Yield(self.com_node(value), lineno=nodelist[0][2])
415+
return Yield(value, lineno=nodelist[0][2])
416416

417417
def raise_stmt(self, nodelist):
418418
# raise: [test [',' test [',' test]]]

Lib/test/test_compiler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def testCompileLibrary(self):
2020
for basename in os.listdir(dir):
2121
if not basename.endswith(".py"):
2222
continue
23-
if not TEST_ALL and random() < 0.98 and basename != "test_with.py":
23+
if not TEST_ALL and random() < 0.98:
2424
continue
2525
path = os.path.join(dir, basename)
2626
if test.test_support.verbose:
@@ -43,6 +43,9 @@ def testCompileLibrary(self):
4343
def testNewClassSyntax(self):
4444
compiler.compile("class foo():pass\n\n","<string>","exec")
4545

46+
def testYieldExpr(self):
47+
compiler.compile("def g(): yield\n\n", "<string>", "exec")
48+
4649
def testLineNo(self):
4750
# Test that all nodes except Module have a correct lineno attribute.
4851
filename = __file__

0 commit comments

Comments
 (0)