diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index d7c6822..0b9af46 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -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): diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 887bda3..35bab3f 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -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):