From 17892556f819cad8aa447e83d45eccc6cb0156f5 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 26 Feb 2020 00:17:44 +0100 Subject: [PATCH] Fix another comment extraction issue --- jedi/api/refactoring/extract.py | 6 +++++- test/refactor/extract_function.py | 33 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/jedi/api/refactoring/extract.py b/jedi/api/refactoring/extract.py index f27fa7d7..f9e2397b 100644 --- a/jedi/api/refactoring/extract.py +++ b/jedi/api/refactoring/extract.py @@ -114,7 +114,11 @@ def _replace(nodes, expression_replacement, extracted, pos, if first_node_leaf is insert_before_leaf: replacement_dct[nodes[0]] = extracted_prefix + expression_replacement else: - replacement_dct[nodes[0]] = first_node_leaf.prefix + expression_replacement + if remaining_prefix is None: + p = first_node_leaf.prefix + else: + p = remaining_prefix + _get_indentation(nodes[0]) + replacement_dct[nodes[0]] = p + expression_replacement replacement_dct[insert_before_leaf] = extracted_prefix + insert_before_leaf.value for node in nodes[1:]: diff --git a/test/refactor/extract_function.py b/test/refactor/extract_function.py index b403d12a..835d2c1c 100644 --- a/test/refactor/extract_function.py +++ b/test/refactor/extract_function.py @@ -242,3 +242,36 @@ def x(v1): x, y = a(v1, v2, v3) #bar return x, y +# -------------------------------------------------- with-range-func-2 +import os +# comment1 +@dec +# comment2 +def x(v1): + #? 2 text {'new_name': 'a', 'until_line': 11, 'until_column': 0} + #foo + v2 = 2 + if 1: + x, y = os.listdir(v1 + v2 * v3) + #bar + return y +x +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +import os +# comment1 +def a(v1, v2, v3): + #foo + v2 = 2 + if 1: + x, y = os.listdir(v1 + v2 * v3) + #bar + return y + + +@dec +# comment2 +def x(v1): + #? 2 text {'new_name': 'a', 'until_line': 11, 'until_column': 0} + y = a(v1, v2, v3) + return y +x