dictionary unpacking treated as syntax error
See original GitHub issueThe 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:
- Created 8 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed, there are Python issues about this problem.
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 👍