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)
|
faked_subscopes.append(f)
|
||||||
return faked_subscopes
|
return faked_subscopes
|
||||||
|
|
||||||
|
def is_scope(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def get_self_attributes(self):
|
def get_self_attributes(self):
|
||||||
return [] # Instance compatibility
|
return [] # Instance compatibility
|
||||||
|
|
||||||
|
|||||||
@@ -478,8 +478,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
|
|||||||
while scope:
|
while scope:
|
||||||
# We don't want submodules to report if we have modules.
|
# We don't want submodules to report if we have modules.
|
||||||
# As well as some non-scopes, which are parents of list comprehensions.
|
# As well as some non-scopes, which are parents of list comprehensions.
|
||||||
if isinstance(scope, pr.SubModule) and scope.parent \
|
if isinstance(scope, pr.SubModule) and scope.parent or not scope.is_scope():
|
||||||
or not isinstance(scope, pr.IsScope):
|
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
continue
|
continue
|
||||||
# `pr.Class` is used, because the parent is never `Class`.
|
# `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)
|
COMMENT, ENDMARKER)
|
||||||
|
|
||||||
|
|
||||||
class Module(pr.Simple, pr.Module):
|
class Module(pr.Module, pr.Simple):
|
||||||
def __init__(self, parsers):
|
def __init__(self, parsers):
|
||||||
super(Module, self).__init__(self, (1, 0))
|
super(Module, self).__init__(self, (1, 0))
|
||||||
self.parsers = parsers
|
self.parsers = parsers
|
||||||
|
|||||||
@@ -191,12 +191,18 @@ class Simple(Base):
|
|||||||
return "<%s: %s@%s,%s>" % \
|
return "<%s: %s@%s,%s>" % \
|
||||||
(type(self).__name__, code, self.start_pos[0], self.start_pos[1])
|
(type(self).__name__, code, self.start_pos[0], self.start_pos[1])
|
||||||
|
|
||||||
|
def is_scope(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class IsScope(Base):
|
class IsScope(Base):
|
||||||
__slots__ = ()
|
__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
|
Super class for the parser tree, which represents the state of a python
|
||||||
text file.
|
text file.
|
||||||
|
|||||||
Reference in New Issue
Block a user