forked from VimPlug/jedi
Start implementing nodes_to_execute in the parser.
This commit is contained in:
@@ -144,6 +144,9 @@ class Base(object):
|
|||||||
# Default is not being a scope. Just inherit from Scope.
|
# Default is not being a scope. Just inherit from Scope.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class Leaf(Base):
|
class Leaf(Base):
|
||||||
__slots__ = ('position_modifier', 'value', 'parent', '_start_pos', 'prefix')
|
__slots__ = ('position_modifier', 'value', 'parent', '_start_pos', 'prefix')
|
||||||
@@ -223,6 +226,9 @@ class Leaf(Base):
|
|||||||
return None
|
return None
|
||||||
return self.parent.children[i - 1]
|
return self.parent.children[i - 1]
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
return []
|
||||||
|
|
||||||
@utf8_repr
|
@utf8_repr
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (type(self).__name__, self.value)
|
return "<%s: %s>" % (type(self).__name__, self.value)
|
||||||
@@ -330,6 +336,9 @@ class Name(Leaf):
|
|||||||
node = node.parent
|
node = node.parent
|
||||||
return indexes
|
return indexes
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
yield self
|
||||||
|
|
||||||
|
|
||||||
class Literal(LeafWithNewLines):
|
class Literal(LeafWithNewLines):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
@@ -488,6 +497,15 @@ class Node(BaseNode):
|
|||||||
super(Node, self).__init__(children)
|
super(Node, self).__init__(children)
|
||||||
self.type = type
|
self.type = type
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
"""
|
||||||
|
For static analysis.
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
for child in self.children:
|
||||||
|
result += child.nodes_to_execute(last_added)
|
||||||
|
return result
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s(%s, %r)" % (self.__class__.__name__, self.type, self.children)
|
return "%s(%s, %r)" % (self.__class__.__name__, self.type, self.children)
|
||||||
|
|
||||||
@@ -699,6 +717,20 @@ class Class(ClassOrFunc):
|
|||||||
sub.get_call_signature(func_name=self.name), docstr)
|
sub.get_call_signature(func_name=self.name), docstr)
|
||||||
return docstr
|
return docstr
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
# Yield itself, class needs to be executed for decorator checks.
|
||||||
|
yield self
|
||||||
|
for param in self.params:
|
||||||
|
if param.default is None:
|
||||||
|
yield param.default
|
||||||
|
else:
|
||||||
|
# metaclass=
|
||||||
|
raise NotImplementedError('Metaclasses not implemented')
|
||||||
|
# care for the class suite:
|
||||||
|
for node_to_execute in self.children[-1].nodes_to_execute(False):
|
||||||
|
yield node_to_execute
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _create_params(parent, argslist_list):
|
def _create_params(parent, argslist_list):
|
||||||
"""
|
"""
|
||||||
@@ -801,6 +833,16 @@ class Function(ClassOrFunc):
|
|||||||
docstr = self.raw_doc
|
docstr = self.raw_doc
|
||||||
return '%s\n\n%s' % (self.get_call_signature(), docstr)
|
return '%s\n\n%s' % (self.get_call_signature(), docstr)
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
# Yield itself, functions needs to be executed for decorator checks.
|
||||||
|
yield self
|
||||||
|
for param in self.params:
|
||||||
|
if param.default is not None:
|
||||||
|
yield param.default
|
||||||
|
# care for the function suite:
|
||||||
|
for node_to_execute in self.children[-1].nodes_to_execute(False):
|
||||||
|
yield node_to_execute
|
||||||
|
|
||||||
|
|
||||||
class Lambda(Function):
|
class Lambda(Function):
|
||||||
"""
|
"""
|
||||||
@@ -826,6 +868,14 @@ class Lambda(Function):
|
|||||||
def yields(self):
|
def yields(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
for param in self.params:
|
||||||
|
if param.default is not None:
|
||||||
|
yield param.default
|
||||||
|
# Care for the lambda test (last child):
|
||||||
|
for node_to_execute in self.children[-1].nodes_to_execute(False):
|
||||||
|
yield node_to_execute
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s@%s>" % (self.__class__.__name__, self.start_pos)
|
return "<%s@%s>" % (self.__class__.__name__, self.start_pos)
|
||||||
|
|
||||||
@@ -833,6 +883,11 @@ class Lambda(Function):
|
|||||||
class Flow(BaseNode):
|
class Flow(BaseNode):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
def nodes_to_execute(self, last_added=False):
|
||||||
|
for child in self.children:
|
||||||
|
for node_to_execute in child.nodes_to_execute(False):
|
||||||
|
yield node_to_execute
|
||||||
|
|
||||||
|
|
||||||
class IfStmt(Flow):
|
class IfStmt(Flow):
|
||||||
type = 'if_stmt'
|
type = 'if_stmt'
|
||||||
|
|||||||
Reference in New Issue
Block a user