diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 04aea04..d87605d 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -439,11 +439,31 @@ class ErrorFinder(Normalizer): def _check_assignment(self, node, is_deletion=False): error = None - if node.type == 'lambdef': + type_ = node.type + if type_ == 'lambdef': error = 'lambda' - elif node.type == 'atom': + elif type_ == 'atom': first, second = node.children[:2] error = _get_comprehension_type(node) + if error is None: + if second.type in ('dictorsetmaker', 'string'): + error = 'literal' + elif first == '(': + if second.type == 'yield_expr': + error = 'yield expression' + elif type_ == 'keyword': + error = 'keyword' + elif type_ == 'operator': + if node.value == '...': + error = 'Ellipsis' + elif type_ == 'comparison': + error = 'comparison' + elif type_ in ('string', 'number'): + error = 'literal' + elif type_ == 'yield_expr': + # This one seems to be a slightly different warning in Python. + message = 'assignment to yield expression not possible' + self._add_syntax_error(message, node) if error is not None: message = "can't %s %s" % ("delete" if is_deletion else "assign to", error) diff --git a/test/test_python_errors.py b/test/test_python_errors.py index da1d165..81dee34 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -81,9 +81,6 @@ def test_indentation_errors(code, positions): 'from .__future__ import whatever', 'def f(x=3, y): pass', 'lambda x=3, y: x', - #'None = 1', - #'(True,) = x', - #'([False], a) = x', #'__debug__ = 1' # Mostly 3.6 relevant '[]: int', @@ -108,6 +105,21 @@ def test_indentation_errors(code, positions): '{x for x in y} = 1', '{x:x for x in y} = 1', '(x for x in y) = 1', + 'None = 1', + '... = 1', + 'a == b = 1', + '{a, b} = 1', + '{a: b} = 1', + '1 = 1', + '"" = 1', + 'b"" = 1', + 'b"" = 1', + '"" "" = 1', + 'def foo(): (yield 1) = 3', + 'def foo(): x = yield 1 = 3' + '', + #'(True,) = x', + #'([False], a) = x', # SyntaxErrors from Python/symtable.c 'def f(x, x): pass',