From 3602c95341117f3a4910d7632361b08ea04db8f0 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 13 Apr 2019 01:52:03 +0200 Subject: [PATCH] Refactor parent_scope a bit --- jedi/parser_utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jedi/parser_utils.py b/jedi/parser_utils.py index 1a68ca4a..51bdd888 100644 --- a/jedi/parser_utils.py +++ b/jedi/parser_utils.py @@ -257,11 +257,19 @@ def get_parent_scope(node, include_flows=False): scope = node.parent if scope is None: return None # It's a module already. - if scope.type in ('funcdef', 'classdef') and scope.name == node: - scope = scope.parent while True: if is_scope(scope) or include_flows and isinstance(scope, tree.Flow): + if scope.type in ('classdef', 'funcdef', 'lambdef'): + index = scope.children.index(':') + if scope.children[index].start_pos >= node.start_pos: + if node.parent.type == 'param' and node.parent.name == node: + pass + elif node.parent.type == 'tfpdef' and node.parent.children[0] == node: + pass + else: + scope = scope.parent + continue return scope scope = scope.parent return scope