forked from VimPlug/jedi
introduce an is_scope function to make it easier to work with scopes
This commit is contained in:
@@ -169,6 +169,9 @@ class CompiledObject(Base):
|
||||
faked_subscopes.append(f)
|
||||
return faked_subscopes
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
def get_self_attributes(self):
|
||||
return [] # Instance compatibility
|
||||
|
||||
|
||||
@@ -478,8 +478,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
|
||||
while scope:
|
||||
# We don't want submodules to report if we have modules.
|
||||
# As well as some non-scopes, which are parents of list comprehensions.
|
||||
if isinstance(scope, pr.SubModule) and scope.parent \
|
||||
or not isinstance(scope, pr.IsScope):
|
||||
if isinstance(scope, pr.SubModule) and scope.parent or not scope.is_scope():
|
||||
scope = scope.parent
|
||||
continue
|
||||
# `pr.Class` is used, because the parent is never `Class`.
|
||||
|
||||
@@ -16,7 +16,7 @@ from jedi.parser.tokenize import (source_tokens, Token, FLOWS, NEWLINE,
|
||||
COMMENT, ENDMARKER)
|
||||
|
||||
|
||||
class Module(pr.Simple, pr.Module):
|
||||
class Module(pr.Module, pr.Simple):
|
||||
def __init__(self, parsers):
|
||||
super(Module, self).__init__(self, (1, 0))
|
||||
self.parsers = parsers
|
||||
|
||||
@@ -191,12 +191,18 @@ class Simple(Base):
|
||||
return "<%s: %s@%s,%s>" % \
|
||||
(type(self).__name__, code, self.start_pos[0], self.start_pos[1])
|
||||
|
||||
def is_scope(self):
|
||||
return False
|
||||
|
||||
|
||||
class IsScope(Base):
|
||||
__slots__ = ()
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
class Scope(Simple, IsScope, DocstringMixin):
|
||||
|
||||
class Scope(IsScope, Simple, DocstringMixin):
|
||||
"""
|
||||
Super class for the parser tree, which represents the state of a python
|
||||
text file.
|
||||
|
||||
Reference in New Issue
Block a user