forked from VimPlug/jedi
start to get rid of parent_stmt
This commit is contained in:
@@ -639,10 +639,9 @@ def follow_call_list(call_list, follow_array=False):
|
|||||||
|
|
||||||
def follow_call(call):
|
def follow_call(call):
|
||||||
"""Follow a call is following a function, variable, string, etc."""
|
"""Follow a call is following a function, variable, string, etc."""
|
||||||
scope = call.parent_stmt.parent
|
|
||||||
path = call.generate_call_path()
|
path = call.generate_call_path()
|
||||||
position = call.parent_stmt.start_pos
|
scope = call.get_parent_until(pr.Scope)
|
||||||
return follow_call_path(path, scope, position)
|
return follow_call_path(path, scope, call.start_pos)
|
||||||
|
|
||||||
|
|
||||||
def follow_call_path(path, scope, position):
|
def follow_call_path(path, scope, position):
|
||||||
|
|||||||
@@ -44,12 +44,22 @@ class Base(object):
|
|||||||
return isinstance(self, cls)
|
return isinstance(self, cls)
|
||||||
|
|
||||||
|
|
||||||
class BasePosition(Base):
|
class Simple(Base):
|
||||||
|
"""
|
||||||
|
The super class for Scope, Import, Name and Statement. Every object in
|
||||||
|
the parser tree inherits from this class.
|
||||||
|
"""
|
||||||
|
__slots__ = ('parent', 'module', '_start_pos', 'use_as_parent', '_end_pos')
|
||||||
|
|
||||||
def __init__(self, module, start_pos, end_pos=(None, None)):
|
def __init__(self, module, start_pos, end_pos=(None, None)):
|
||||||
self.module = module
|
self.module = module
|
||||||
self._start_pos = start_pos
|
self._start_pos = start_pos
|
||||||
self._end_pos = end_pos
|
self._end_pos = end_pos
|
||||||
|
|
||||||
|
self.parent = None
|
||||||
|
# use this attribute if parent should be something else than self.
|
||||||
|
self.use_as_parent = self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def start_pos(self):
|
def start_pos(self):
|
||||||
return self.module.line_offset + self._start_pos[0], self._start_pos[1]
|
return self.module.line_offset + self._start_pos[0], self._start_pos[1]
|
||||||
@@ -68,20 +78,6 @@ class BasePosition(Base):
|
|||||||
def end_pos(self, value):
|
def end_pos(self, value):
|
||||||
self._end_pos = value
|
self._end_pos = value
|
||||||
|
|
||||||
|
|
||||||
class Simple(BasePosition):
|
|
||||||
"""
|
|
||||||
The super class for Scope, Import, Name and Statement. Every object in
|
|
||||||
the parser tree inherits from this class.
|
|
||||||
"""
|
|
||||||
__slots__ = ('parent', 'module', '_start_pos', 'use_as_parent', '_end_pos')
|
|
||||||
|
|
||||||
def __init__(self, module, start_pos, end_pos=(None, None)):
|
|
||||||
super(Simple, self).__init__(module, start_pos, end_pos)
|
|
||||||
self.parent = None
|
|
||||||
# use this attribute if parent should be something else than self.
|
|
||||||
self.use_as_parent = self
|
|
||||||
|
|
||||||
@Python3Method
|
@Python3Method
|
||||||
def get_parent_until(self, classes=(), reverse=False,
|
def get_parent_until(self, classes=(), reverse=False,
|
||||||
include_current=True):
|
include_current=True):
|
||||||
@@ -811,7 +807,7 @@ class Statement(Simple):
|
|||||||
is_chain = False
|
is_chain = False
|
||||||
close_brackets = False
|
close_brackets = False
|
||||||
brackets = {'(': Array.TUPLE, '[': Array.LIST, '{': Array.SET}
|
brackets = {'(': Array.TUPLE, '[': Array.LIST, '{': Array.SET}
|
||||||
closing_brackets = [')', '}', ']']
|
closing_brackets = ')', '}', ']'
|
||||||
|
|
||||||
token_iterator = enumerate(self.token_list)
|
token_iterator = enumerate(self.token_list)
|
||||||
for i, tok_temp in token_iterator:
|
for i, tok_temp in token_iterator:
|
||||||
@@ -911,7 +907,7 @@ class Param(Statement):
|
|||||||
return n[0]
|
return n[0]
|
||||||
|
|
||||||
|
|
||||||
class Call(BasePosition):
|
class Call(Simple):
|
||||||
"""
|
"""
|
||||||
`Call` contains a call, e.g. `foo.bar` and owns the executions of those
|
`Call` contains a call, e.g. `foo.bar` and owns the executions of those
|
||||||
calls, which are `Array`s.
|
calls, which are `Array`s.
|
||||||
@@ -1001,10 +997,8 @@ class Array(Call):
|
|||||||
DICT = 'dict'
|
DICT = 'dict'
|
||||||
SET = 'set'
|
SET = 'set'
|
||||||
|
|
||||||
def __init__(self, start_pos, arr_type=NOARRAY, parent_stmt=None,
|
def __init__(self, start_pos, arr_type=NOARRAY, parent=None, values=None):
|
||||||
parent=None, values=None):
|
super(Array, self).__init__(None, arr_type, start_pos, parent)
|
||||||
super(Array, self).__init__(None, arr_type, start_pos, parent_stmt,
|
|
||||||
parent)
|
|
||||||
self.values = values if values else []
|
self.values = values if values else []
|
||||||
self.keys = []
|
self.keys = []
|
||||||
self.end_pos = None, None
|
self.end_pos = None, None
|
||||||
|
|||||||
Reference in New Issue
Block a user