forked from VimPlug/jedi
More cleanups in the parser.
This commit is contained in:
@@ -191,7 +191,7 @@ def follow_param(module_context, param):
|
|||||||
[p for param_str in _search_param_in_docstr(docstring, str(param.name))
|
[p for param_str in _search_param_in_docstr(docstring, str(param.name))
|
||||||
for p in _evaluate_for_statement_string(module_context, param_str)]
|
for p in _evaluate_for_statement_string(module_context, param_str)]
|
||||||
)
|
)
|
||||||
func = param.parent_function
|
func = param.get_parent_function()
|
||||||
types = eval_docstring(func.raw_doc)
|
types = eval_docstring(func.raw_doc)
|
||||||
if func.name.value == '__init__':
|
if func.name.value == '__init__':
|
||||||
cls = search_ancestor(func, 'classdef')
|
cls = search_ancestor(func, 'classdef')
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class NameFinder(object):
|
|||||||
if self._context.predefined_names:
|
if self._context.predefined_names:
|
||||||
# TODO is this ok? node might not always be a tree.Name
|
# TODO is this ok? node might not always be a tree.Name
|
||||||
node = self._name
|
node = self._name
|
||||||
while node is not None and not isinstance(node, tree.IsScope):
|
while node is not None and not node.is_scope():
|
||||||
node = node.parent
|
node = node.parent
|
||||||
if node.type in ("if_stmt", "for_stmt", "comp_for"):
|
if node.type in ("if_stmt", "for_stmt", "comp_for"):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -711,15 +711,6 @@ class ErrorLeaf(LeafWithNewLines):
|
|||||||
(type(self).__name__, self.original_type, repr(self.value), self.start_pos)
|
(type(self).__name__, self.original_type, repr(self.value), self.start_pos)
|
||||||
|
|
||||||
|
|
||||||
class IsScopeMeta(type):
|
|
||||||
def __instancecheck__(self, other):
|
|
||||||
return other.is_scope()
|
|
||||||
|
|
||||||
|
|
||||||
class IsScope(use_metaclass(IsScopeMeta)):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Scope(BaseNode, DocstringMixin):
|
class Scope(BaseNode, 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
|
||||||
@@ -1635,9 +1626,8 @@ class Param(BaseNode):
|
|||||||
def position_nr(self):
|
def position_nr(self):
|
||||||
return self.parent.children.index(self) - 1
|
return self.parent.children.index(self) - 1
|
||||||
|
|
||||||
@property
|
def get_parent_function(self):
|
||||||
def parent_function(self):
|
return search_ancestor(self, ('funcdef', 'lambda'))
|
||||||
return self.get_parent_until(IsScope)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
default = '' if self.default is None else '=%s' % self.default.get_code()
|
default = '' if self.default is None else '=%s' % self.default.get_code()
|
||||||
|
|||||||
Reference in New Issue
Block a user