question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dictionary unpacking treated as syntax error

See original GitHub issue

The parser from lib2to3 doesn’t appear to support the ** operator.

Windows 7 64 bit, Python 3.5.1 64 bit.

Minimal example:

v1={1:2,3:4}
v2={**v1,5:6}
print(v2)

It works as expected:

bash-4.3$ python example.py
{1: 2, 3: 4, 5: 6}

but it crashes yapf:

bash-4.3$ yapf example.py
Traceback (most recent call last):
  File "c:\python35\lib\site-packages\yapf\yapflib\pytree_utils.py", line 100, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "c:\python35\lib\lib2to3\pgen2\driver.py", line 106, in parse_string
    return self.parse_tokens(tokens, debug)
  File "c:\python35\lib\lib2to3\pgen2\driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "c:\python35\lib\lib2to3\pgen2\parse.py", line 159, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=36, value='**', context=('', (2, 4))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python35\Scripts\yapf.exe\__main__.py", line 9, in <module>
  File "c:\python35\lib\site-packages\yapf\__init__.py", line 250, in run_main
    sys.exit(main(sys.argv))
  File "c:\python35\lib\site-packages\yapf\__init__.py", line 168, in main
    verify=args.verify)
  File "c:\python35\lib\site-packages\yapf\__init__.py", line 212, in FormatFiles
    logger=logging.warning)
  File "c:\python35\lib\site-packages\yapf\yapflib\yapf_api.py", line 90, in FormatFile
    verify=verify)
  File "c:\python35\lib\site-packages\yapf\yapflib\yapf_api.py", line 123, in FormatCode
    tree = pytree_utils.ParseCodeToTree(unformatted_source)
  File "c:\python35\lib\site-packages\yapf\yapflib\pytree_utils.py", line 106, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "c:\python35\lib\lib2to3\pgen2\driver.py", line 106, in parse_string
    return self.parse_tokens(tokens, debug)
  File "c:\python35\lib\lib2to3\pgen2\driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "c:\python35\lib\lib2to3\pgen2\parse.py", line 159, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=36, value='**', context=('', (2, 4))
bash-4.3$


Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lorenzogatticommented, Mar 14, 2016

Indeed, there are Python issues about this problem.

0reactions
deterralbacommented, Jan 12, 2018

For my fellow Googlers: I had the same error: lib2to3.pgen2.parse.ParseError: bad input: type=36, value='**', with python 3.5.2 on ubuntu.

I installed 3.6.4 on a virtualenv and it fixed the issue.

PS: hey the dev team, yapf is awesome and you should feel awesome 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

'SyntaxError' while unpacking dict in Python - Stack Overflow
1 Answer 1 ... This syntax was released with Python 3.5 as the part of PEP 448 - Additional Unpacking Generalizations. ... {*...,...
Read more >
Can't unpack values of dictionary with ** - Python Forum
I've seen similar examples in 4.7.5 Unpacking argument lists, but my somehow don't work. ... SyntaxError: invalid syntax ...
Read more >
Issue 41064: Specialise syntax error of **dict in f-string field
msg371995 ‑ (view) Author: JNCressey (JNCressey) Date: 2020‑06‑21 12:32 msg371999 ‑ (view) Author: E. Paine (epaine) * Date: 2020‑06‑21 15:29 msg372007 ‑ (view) Author: Terry...
Read more >
Defining Your Own Python Function
Argument Tuple Packing; Argument Tuple Unpacking; Argument Dictionary Packing ... f(6, item='bananas', 1.74) SyntaxError: positional argument follows ...
Read more >
Arrays - Manual - PHP
A short array syntax exists which replaces array() with [] . ... The fallback to treat an undefined constant as bare string issues...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found