mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Add issue 'dict unpacking cannot be used in dict comprehension'
This commit is contained in:
@@ -212,6 +212,15 @@ class ErrorFinder(Normalizer):
|
||||
if child not in (',', ')') and not child.star_count]
|
||||
if len(after) == 0:
|
||||
self._add_syntax_error("named arguments must follow bare *", leaf)
|
||||
elif leaf.value == '**':
|
||||
if leaf.parent.type == 'dictorsetmaker':
|
||||
comp_for = leaf.get_next_sibling().get_next_sibling()
|
||||
if comp_for is not None and comp_for.type == 'comp_for':
|
||||
# {**{} for a in [1]}
|
||||
message = "dict unpacking cannot be used in dict comprehension"
|
||||
# TODO probably this should get a better end_pos including
|
||||
# the next sibling of leaf.
|
||||
self._add_syntax_error(message, leaf)
|
||||
return ''
|
||||
|
||||
def _add_indentation_error(self, message, spacing):
|
||||
|
||||
@@ -110,6 +110,7 @@ def test_python_exception_matches(code):
|
||||
('def x(*): pass', '3.5'),
|
||||
('async def foo():\n def nofoo():[x async for x in []]', '3.6'),
|
||||
('[*[] for a in [1]]', '3.5'),
|
||||
('{**{} for a in [1]}', '3.5'),
|
||||
]
|
||||
)
|
||||
def test_python_exception_matches_version(code, version):
|
||||
|
||||
Reference in New Issue
Block a user