Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended unpacking unsupported in many contexts #149

Open
lordmauve opened this issue Mar 27, 2019 · 2 comments
Open

Extended unpacking unsupported in many contexts #149

lordmauve opened this issue Mar 27, 2019 · 2 comments

Comments

@lordmauve
Copy link

Baron only supports PEP-3132 extended unpacking in assignment context, ie. it can parse a, *b = xs etc

This syntax also valid in various other contexts. For example, for-loop context:

>>> xs = [range(10), range(0, 20, 2)]
>>> for a, *b in xs:
...     print(b)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 4, 6, 8, 10, 12, 14, 16, 18]

but I get an error in baron==0.9

>>> baron.parse('for a, *b in rs:\n    print(b)\n')
Traceback (most recent call last):
...
baron.parser.ParsingError: Error, got an unexpected token STAR here:

   1 for a, *<---- here

I've tested this syntax and found it is valid in comprehensions...

[b for a, *b in xs]

...in with-blocks...

... @contextmanager
... def ctx():
...     yield range(10)
...
>>> with ctx() as (a, *b):
>>>     print(b)
[1, 2, 3, 4, 5, 6, 7, 8, 9]

...and is also available recursively...

>>> (a, *b), (c, *d), (e, *f) = [range(3)] * 3
>>> a, b, c, d, e, f
(0, [1, 2], 0, [1, 2], 0, [1, 2])
>>> a, *(*b, c) = range(5)
>>> a, b, c
(0, [1, 2, 3], 4)

...all of which are currently unsupported by baron.

@lordmauve lordmauve changed the title Extended unpacking unsupported in all contexts Extended unpacking unsupported in many contexts Mar 27, 2019
@DylanLukes
Copy link

DylanLukes commented Jan 25, 2020

+1 on this. Probably the simplest case I can find is:

(1, *(2, 3))
ParsingError: Error, got an unexpected token STAR here:

   1 [b for a, *<---- here

@asterbini
Copy link

+1 for me also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants