From 089a4713e3d59959a8f2281cb9034650bd34e02c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 13 Jun 2020 01:35:58 +0200 Subject: [PATCH] Fix a small extract_variable issue, fixes #1611 --- jedi/api/refactoring/extract.py | 5 +++-- jedi/third_party/django-stubs | 2 +- test/refactor/extract_variable.py | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jedi/api/refactoring/extract.py b/jedi/api/refactoring/extract.py index 15bc6527..ad2ded9c 100644 --- a/jedi/api/refactoring/extract.py +++ b/jedi/api/refactoring/extract.py @@ -9,7 +9,6 @@ from jedi.common import indent_block from jedi.parser_utils import function_is_classmethod, function_is_staticmethod -_EXTRACT_USE_PARENT = EXPRESSION_PARTS + ['trailer'] _DEFINITION_SCOPES = ('suite', 'file_input') _VARIABLE_EXCTRACTABLE = EXPRESSION_PARTS + \ ('atom testlist_star_expr testlist test lambdef lambdef_nocond ' @@ -57,7 +56,9 @@ def _find_nodes(module_node, pos, until_pos): if _is_not_extractable_syntax(start_node): start_node = start_node.parent - while start_node.parent.type in _EXTRACT_USE_PARENT: + if start_node.parent.type == 'trailer': + start_node = start_node.parent.parent + while start_node.parent.type in EXPRESSION_PARTS: start_node = start_node.parent nodes = [start_node] diff --git a/jedi/third_party/django-stubs b/jedi/third_party/django-stubs index 92c8dfc9..fd057010 160000 --- a/jedi/third_party/django-stubs +++ b/jedi/third_party/django-stubs @@ -1 +1 @@ -Subproject commit 92c8dfc93f840b936e33eb3f1770293627ac0f15 +Subproject commit fd057010f6cbf176f57d1099e82be46d39b99cb9 diff --git a/test/refactor/extract_variable.py b/test/refactor/extract_variable.py index 772bee76..880b528c 100644 --- a/test/refactor/extract_variable.py +++ b/test/refactor/extract_variable.py @@ -17,6 +17,15 @@ def test(): a = 30 + b return test(100, (a, c) + 1) # -------------------------------------------------- simple-3 +foo = 3.1 +#? 8 text {'new_name': 'bar'} +x = int(foo + 1) +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +foo = 3.1 +#? 8 text {'new_name': 'bar'} +bar = foo + 1 +x = int(bar) +# -------------------------------------------------- simple-4 #? 13 text {'new_name': 'zzx.x'} test(100, {1 |1: 2 + 3}) # ++++++++++++++++++++++++++++++++++++++++++++++++++