diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index ee92c21a..49a58db6 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -113,7 +113,9 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY): operator = None for check_prio, check in enumerate(PythonGrammar.ORDER): if check_prio >= priority: - break # respect priorities. + # respect priorities. + iterator.push_back(el) + return left try: match_index = check.index(el) @@ -137,6 +139,8 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY): _syntax_error(el) continue + if operator == '**': + check_prio += 1 # to the power of is right-associative right = _check_operator(iterator, check_prio) if right is not None: left = Precedence(left, str(operator), right) diff --git a/test/test_evaluate/test_precedence.py b/test/test_evaluate/test_precedence.py index 9d7630ee..14aa3dea 100644 --- a/test/test_evaluate/test_precedence.py +++ b/test/test_evaluate/test_precedence.py @@ -19,6 +19,7 @@ def parse_tree(statement_string): def test_simple(): assert parse_tree('1+2') == (1, '+', 2) assert parse_tree('+2') == (None, '+', 2) + assert parse_tree('1+2-3') == ((1, '+', 2), '-', 3) def test_prefixed(): @@ -38,8 +39,15 @@ def test_invalid(): assert parse_tree('1 not - 1') == (1, '-', 1) assert parse_tree('1 - not ~1') == (1, '-', (None, '~', 1)) + # not not allowed + assert parse_tree('1 is not not 1') == (1, 'is not', 1) + def test_multi_part(): assert parse_tree('1 not in 2') == (1, 'not in', 2) assert parse_tree('1 is not -1') == (1, 'is not', (None, '-', 1)) assert parse_tree('1 is 1') == (1, 'is', 1) + + +def test_power(): + assert parse_tree('2 ** 3 ** 4') == (2, '**', (3, '**', 4))