summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_named_expressions.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-11-16 23:38:58 (GMT)
committerGitHub <noreply@github.com>2020-11-16 23:38:58 (GMT)
commit2b800ef809eefbc96a536e4b43a8285f2353f64d (patch)
treea7324a40ab4f2e34a8581fd670554dde2688ada4 /Lib/test/test_named_expressions.py
parentcf70854f10096446115408b5a94030b30594a459 (diff)
downloadcpython-2b800ef809eefbc96a536e4b43a8285f2353f64d.zip
cpython-2b800ef809eefbc96a536e4b43a8285f2353f64d.tar.gz
cpython-2b800ef809eefbc96a536e4b43a8285f2353f64d.tar.bz2
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 cb3e5ed0716114393696ec7201e51fe0595eab4f)
Diffstat (limited to 'Lib/test/test_named_expressions.py')
-rw-r--r--Lib/test/test_named_expressions.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_named_expressions.py b/Lib/test/test_named_expressions.py
index c813830..d614f32 100644
--- a/Lib/test/test_named_expressions.py
+++ b/Lib/test/test_named_expressions.py
@@ -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()