[Python-Dev] Python 3.0 grammar ambiguous?

"Martin v. Löwis" martin at v.loewis.de
Sun Mar 8 21:20:34 CET 2009


Fabio Zadrozny wrote:
> I was wondering how does Python
> disambiguate that... anyone has any pointers on it?

That is easy to answer:

py> parser.expr("f(*x)").totuple()
(258, (326, (303, (304, (305, (306, (307, (309, (310, (311, (312, (313,
(314, (315, (316, (317, (1, 'f')), (321, (7, '('), (329, (16, '*'),
(303, (304, (305, (306, (307, (309, (310, (311, (312, (313, (314, (315,
(316, (317, (1, 'x')))))))))))))))), (8, ')')))))))))))))))), (4, ''),
(0, ''))
py> symbol.arglist
329

So much for the "how", I don't know why it makes this choice; notice
that this is the better choice, though:

py> f((*x))
  File "<stdin>", line 1
SyntaxError: can use starred expression only as assignment target

Regards,
Martin


More information about the Python-Dev mailing list