[issue32012] Disallow ambiguous syntax f(x for x in [1],)
Henk-Jaap Wagenaar
report at bugs.python.org
Mon Nov 13 10:19:50 EST 2017
Henk-Jaap Wagenaar <wagenaarhenkjaap at gmail.com> added the comment:
[As a follow-on, should I open a new issue/discuss on python-dev? Willing to help out with a solution on way or another! I know https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence, "In my head" <> "Should be the case" etc. very much applies.]
In my head
@...
def foo(): pass
is equivalent to
def _foo(): pass
foo = ...()
del _foo
However the following shows this is not the case:
@0
def foo(): pass
throws a syntax error, whereas
def _foo(): pass
foo = 0(_foo)
throws a type error. This might seem silly, but it is still unexpected.
https://docs.python.org/3/reference/compound_stmts.html#grammar-token-decorator has
decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
which in my head is
decorator ::= "@" atom NEWLINE
Similarly for classes: https://docs.python.org/3/reference/compound_stmts.html#class-definitions
inheritance ::= "(" [argument_list] ")"
which allows for keyword arguments (does that make any sense!?). In my head it is (compare with call: https://docs.python.org/3/reference/expressions.html#calls)
inheritance ::= "(" [positional_arguments [","] | comprehension] ")"
[Tangentially related, this is how I originally got onto the mailing lists, my unhappiness with the definition of the for statement (https://docs.python.org/3/reference/compound_stmts.html#the-for-statement):
for_stmt ::= "for" target_list "in" expression_list ":" suite ["else" ":" suite]
Which I would expect to be:
for_stmt ::= comp_for ":" suite ["else" ":" suite]
so you could e.g. have if statements.
]
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32012>
_______________________________________
More information about the Python-bugs-list
mailing list