berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

Missing parentheses in dictionary unpacking #199

Closed Kodiologist closed 2 years ago

Kodiologist commented 3 years ago
>>> {**(0 or {})}
{}
>>> astor.to_source(ast.parse("{**(0 or {})}"))
'{**0 or {}}\n'
>>> {**0 or {}}
  File "<stdin>", line 1
    {**0 or {}}
         ^
SyntaxError: invalid syntax

Originally reported by @martibi at https://github.com/hylang/hy/issues/2156.

Kodiologist commented 3 years ago

Contrast:

>>> ast.unparse(ast.parse("{**(0 or {})}"))
'{**(0 or {})}'

so we can probably just do whatever Python does for this.