mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Refactor parent_scope a bit
This commit is contained in:
@@ -257,11 +257,19 @@ def get_parent_scope(node, include_flows=False):
|
|||||||
scope = node.parent
|
scope = node.parent
|
||||||
if scope is None:
|
if scope is None:
|
||||||
return None # It's a module already.
|
return None # It's a module already.
|
||||||
if scope.type in ('funcdef', 'classdef') and scope.name == node:
|
|
||||||
scope = scope.parent
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if is_scope(scope) or include_flows and isinstance(scope, tree.Flow):
|
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
|
return scope
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return scope
|
return scope
|
||||||
|
|||||||
Reference in New Issue
Block a user