[Python-Dev] Disallow ambiguous syntax f(x for x in [1],)

Serhiy Storchaka storchaka at gmail.com
Mon Nov 13 02:22:11 EST 2017

13.11.17 02:00, Guido van Rossum пише:
> It's hard to keep those two in sync, since the actual Grammar file is 
> constrained by being strictly LL(1)... Can you get someone else to 
> review the implementation?

I haven't change the grammar, just have changed checks in the CST to AST 
transformer. Maybe it would be better to change the grammar, but I'm not 
expert in this. Maybe Benjamin could provide better solution.

There are other related differences between language specification and 
the implementation. The following examples are valid syntax:

     @deco(x for x in [1])
     def f(): ...

     class C(x for x in [1]): ...

The latter always raises a TypeError at runtime ("cannot create 
'generator' instances"), but is compiled successfully.

More information about the Python-Dev mailing list