From da935baa99a781fb8adf090d595369499e268f10 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 23 Feb 2020 12:06:37 +0100 Subject: [PATCH] Some more extract improvements --- jedi/api/refactoring.py | 10 +++++++++- test/refactor/extract_function.py | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jedi/api/refactoring.py b/jedi/api/refactoring.py index 04c2e934..4e936ff8 100644 --- a/jedi/api/refactoring.py +++ b/jedi/api/refactoring.py @@ -442,8 +442,16 @@ def _find_non_global_names(context, nodes): children = node.children except AttributeError: if node.type == 'name': - yield node.value + name_definitions = context.goto(node, node.start_pos) + if not name_definitions \ + or any(not n.parent_context.is_module() or n.api_type == 'param' + for n in name_definitions): + yield node.value else: + # We only want to check foo in foo.bar + if node.type == 'trailer' and node.children[0] == '.': + continue + for x in _find_non_global_names(context, children): # Python 2... yield x diff --git a/test/refactor/extract_function.py b/test/refactor/extract_function.py index 3e4330cf..62b27ce4 100644 --- a/test/refactor/extract_function.py +++ b/test/refactor/extract_function.py @@ -1,10 +1,12 @@ # -------------------------------------------------- in-module-1 +glob = 3 #? 11 text {'new_name': 'a'} -test(100, (30 + b, c) + 1) +test(100, (glob.a + b, c) + 1) # ++++++++++++++++++++++++++++++++++++++++++++++++++ +glob = 3 #? 11 text {'new_name': 'a'} def a(b): - return 30 + b + return glob.a + b test(100, (a(b), c) + 1)