bpo-42374: Allow unparenthesized walrus in genexps (GH-23319) (GH-23329)

This fixes a regression that was introduced by the new parser.

(cherry picked from commit cb3e5ed071)
This commit is contained in:
Lysandros Nikolaou 2020-11-17 01:38:58 +02:00 committed by GitHub
parent cf70854f10
commit 2b800ef809
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -513,6 +513,15 @@ spam()"""
self.assertEqual(nonlocal_var, None)
f()
def test_named_expression_scope_in_genexp(self):
a = 1
b = [1, 2, 3, 4]
genexp = (c := i + a for i in b)
self.assertNotIn("c", locals())
for idx, elem in enumerate(genexp):
self.assertEqual(elem, b[idx] + a)
if __name__ == "__main__":
unittest.main()