1
0
forked from VimPlug/jedi

Move is_scope and get_parent_scope out of the parser.

This commit is contained in:
Dave Halter
2017-05-07 14:58:53 +02:00
parent 0882849e65
commit 536e62e67d
10 changed files with 44 additions and 42 deletions

View File

@@ -217,3 +217,21 @@ def get_following_comment_same_line(node):
comment = comment[:comment.index("\n")]
return comment
def is_scope(node):
return node.type in ('file_input', 'classdef', 'funcdef', 'lambdef', 'comp_for')
def get_parent_scope(node, include_flows=False):
"""
Returns the underlying scope.
"""
scope = node.parent
while scope is not None:
if include_flows and isinstance(scope, tree.Flow):
return scope
if is_scope(scope):
break
scope = scope.parent
return scope