astpp.parseprint gives a wrong value sometimes, in case of Starred nodes
astpp.prettyprint() seems to fail for specific (not all) cases of Starred nodes. In my tests, it works for Store contexts, but fails for Load ones.
Repro Steps:
>>> from astpp import parseprint
>>> parseprint('a,b,c = [ *[1,2], 3]')
Module(body=[
Assign(targets=[
Tuple(elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store()),
Name(id='c', ctx=Store()),
], ctx=Store()),
], value=List(elts=[
Starred(value=List(elts=[
Num(n=1),
Num(n=2),
], ctx=Load()), ctx=Load()),
Num(n=3),
], ctx=Load())),
])
For the same input text, however, the AST module output differs.
>>> import ast
>>> t = ast.parse('a,b,c = [ *[1,2], 3]')
>>> t.body[0].value
<_ast.Tuple at 0x7f9ec2bc6278>
So the t.body[0].value
shows List
node in one case and Tuple
node in another.
Do let me know if any more details are needed.
PS: I've been using this excellent AST pretty printer (and even better documentation) for the past few days. It's great!
Comments (3)
-
repo owner -
reporter No, I ran them in the same shell, should've taken a screenshot.
However, when I try the same thing in a fresh shell, I do see that they're the same. I'm not sure what happened, so I'm closing this for now. Sorry for wasting your time.
If I see this again I'll investigate more to find more concrete repro steps, and share results.
-
reporter - changed status to invalid
Could not reliably reproduce this, resolving as invalid
- Log in to comment
That's weird.
parseprint
is just calling astparse and then printing the results. I see aList
for both ways:Is it possible you ran them in two different versions of Python?