mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
cf70854f10
commit
2b800ef809
4 changed files with 18 additions and 7 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue