[issue40631] PEG Parser: Cannot used starred expression in parenthesised expr

Guido van Rossum report at bugs.python.org
Wed Dec 30 18:41:18 EST 2020


Guido van Rossum <guido at python.org> added the comment:

> It makes sense to me to be able to do `(*a), b` if I can do `*a, b`, but I don't really have a strong opinion on it.

I disagree. *a is not an expression, so the normal rules for parenthesizing those don't apply. I've always thought of *a as a feature of the "comma" syntax. Note too that (**a) is not valid and never was. Also note that 2.7 doesn't support f((*a)). In fact 3.4 doesn't either -- but 3.5 does.

I don't know how this slipped into earlier Python 3 versions -- apparently there aren't tests for this, and it's not used in popular 3rd code either, or we would have found out when we first implemented PEP 617.

Most likely it's due to the general problem where the parser would just accept parenthesized stuff in various places where it shouldn't (e.g. also f(a=1) could be spelled as f((a)=1) -- this was fixed in 3.8).

> Also the current behavior allows `(*x), y = 1` assignment. If `(*x)` is to be totally disallowed, `(*x), y = 1` should also be rejected.

I agree.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40631>
_______________________________________


More information about the Python-bugs-list mailing list