From 52e3db4834aaa399bcbf4445fec2e37e3a10d6cb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 6 Jul 2018 01:24:38 +0200 Subject: [PATCH] Fix an issue in the diff parser Forgot to check for functions/classes that were part of a decorator/async func. Fixes https://github.com/davidhalter/jedi/issues/1132 --- parso/python/diff.py | 4 +++- test/test_diff_parser.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/parso/python/diff.py b/parso/python/diff.py index 2197548..323f2dd 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -570,7 +570,9 @@ class _NodesStack(object): self._tos = _NodesStackNode(tree_node, self._tos) self._tos.add(list(tree_node.children)) self._update_tos(tree_node.children[-1]) - elif tree_node.type in ('classdef', 'funcdef'): + elif tree_node.type in ('decorated', 'classdef', 'funcdef', + 'async_funcdef') \ + or tree_node.type == 'async_stmt' and tree_node.children[0].type == 'funcdef': self._update_tos(tree_node.children[-1]) def close(self): diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index ec752ca..0c0a8b8 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -507,3 +507,22 @@ def test_endmarker_newline(differ): def test_newlines_at_end(differ): differ.initialize('a\n\n') differ.parse('a\n', copies=1) + + +def test_end_newline_with_decorator(differ): + code = dedent('''\ + @staticmethod + def spam(): + import json + json.l''') + + differ.initialize(code) + module = differ.parse(code + '\n', copies=0) + decorated, endmarker = module.children + assert decorated.type == 'decorated' + decorator, func = decorated.children + suite = func.children[-1] + assert suite.type == 'suite' + newline, first_stmt, second_stmt = suite.children + assert first_stmt.get_code() == ' import json\n' + assert second_stmt.get_code() == ' json.l\n'