evhub / coconut

Simple, elegant, Pythonic functional programming.
http://coconut-lang.org
Apache License 2.0
4.04k stars 120 forks source link

Walruses aren't allowed in places where they should be #820

Closed kg583 closed 7 months ago

kg583 commented 7 months ago

The following walruses raise parser errors, despite being valid Python:

[1, 2, 3][i := 0]
sum(i := 0 for _ in [1, 2, 3]) 

Note that the former only happens in a __getitem__ call; a literal like [i := 0] is parsed correctly.

evhub commented 7 months ago

Ah, looks like I missed one of the places where 3.10 added support for named expressions. Simple workaround is to add parentheses as in <=3.9, but this should now work with --target 3.10+ as of coconut-develop>=3.0.4-post_dev15.