forked from VimPlug/jedi
Add a names_dict to scopes. This is good for the future parser and now useful to process self.foo and other stuff.
This commit is contained in:
@@ -164,6 +164,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
# because to follow them and their self variables is too
|
# because to follow them and their self variables is too
|
||||||
# complicated.
|
# complicated.
|
||||||
sub = self._get_method_execution(sub)
|
sub = self._get_method_execution(sub)
|
||||||
|
print(sub.get_names_dict())
|
||||||
for n in sub.get_defined_names():
|
for n in sub.get_defined_names():
|
||||||
# Only names with the selfname are being added.
|
# Only names with the selfname are being added.
|
||||||
# It is also important, that they have a len() of 2,
|
# It is also important, that they have a len() of 2,
|
||||||
@@ -579,6 +580,10 @@ class FunctionExecution(Executed):
|
|||||||
break
|
break
|
||||||
return types
|
return types
|
||||||
|
|
||||||
|
@underscore_memoization
|
||||||
|
def get_names_dict(self):
|
||||||
|
return self.
|
||||||
|
|
||||||
@memoize_default(default=())
|
@memoize_default(default=())
|
||||||
def _get_params(self):
|
def _get_params(self):
|
||||||
"""
|
"""
|
||||||
@@ -631,7 +636,7 @@ class FunctionExecution(Executed):
|
|||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def returns(self):
|
def returns(self):
|
||||||
return self._copy_list('returns')
|
return self._copy_list(self)
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ class Parser(object):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
self.module.used_names[tok_name] = set([simple])
|
self.module.used_names[tok_name] = set([simple])
|
||||||
self.module.temp_used_names = []
|
self.module.temp_used_names = []
|
||||||
|
if isinstance(simple, pr.Statement):
|
||||||
|
for name, call in simple.get_names_dict().items():
|
||||||
|
self._scope.add_name_call(name, call)
|
||||||
|
|
||||||
def _parse_dotted_name(self, pre_used_token=None):
|
def _parse_dotted_name(self, pre_used_token=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ class Scope(Simple, DocstringMixin):
|
|||||||
:type start_pos: tuple(int, int)
|
:type start_pos: tuple(int, int)
|
||||||
"""
|
"""
|
||||||
__slots__ = ('subscopes', 'imports', 'statements', '_doc_token', 'asserts',
|
__slots__ = ('subscopes', 'imports', 'statements', '_doc_token', 'asserts',
|
||||||
'returns', 'is_generator')
|
'returns', 'is_generator', '_names_dict')
|
||||||
|
|
||||||
def __init__(self, module, start_pos):
|
def __init__(self, module, start_pos):
|
||||||
super(Scope, self).__init__(module, start_pos)
|
super(Scope, self).__init__(module, start_pos)
|
||||||
@@ -256,11 +256,19 @@ class Scope(Simple, DocstringMixin):
|
|||||||
# Needed here for fast_parser, because the fast_parser splits and
|
# Needed here for fast_parser, because the fast_parser splits and
|
||||||
# returns will be in "normal" modules.
|
# returns will be in "normal" modules.
|
||||||
self.returns = []
|
self.returns = []
|
||||||
|
self._names_dict = defaultdict(lambda: [])
|
||||||
self.is_generator = False
|
self.is_generator = False
|
||||||
|
|
||||||
def is_scope(self):
|
def is_scope(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def add_name_call(self, name, call):
|
||||||
|
"""Add a name to the names_dict."""
|
||||||
|
self._names_dict[name].append(call)
|
||||||
|
|
||||||
|
def get_names_dict(self):
|
||||||
|
return self._names_dict
|
||||||
|
|
||||||
def add_scope(self, sub, decorators):
|
def add_scope(self, sub, decorators):
|
||||||
sub.parent = self.use_as_parent
|
sub.parent = self.use_as_parent
|
||||||
sub.decorators = decorators
|
sub.decorators = decorators
|
||||||
@@ -672,6 +680,10 @@ class Flow(Scope):
|
|||||||
s.parent = self.use_as_parent
|
s.parent = self.use_as_parent
|
||||||
self.set_vars = []
|
self.set_vars = []
|
||||||
|
|
||||||
|
def add_name_call(self, name, call):
|
||||||
|
"""Add a name to the names_dict."""
|
||||||
|
self.parent.add_name_call(name, call)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
return self._parent
|
return self._parent
|
||||||
@@ -996,12 +1008,11 @@ class Statement(Simple, DocstringMixin):
|
|||||||
c = call
|
c = call
|
||||||
# Check if there's an execution in it, if so this is
|
# Check if there's an execution in it, if so this is
|
||||||
# not a set_var.
|
# not a set_var.
|
||||||
while c:
|
while True:
|
||||||
if isinstance(c.next, Array):
|
if c.next is None or isinstance(c.next, Array):
|
||||||
break
|
break
|
||||||
c = c.next
|
c = c.next
|
||||||
else:
|
dct[unicode(c.name)] = call
|
||||||
dct[unicode(c.name)] = call
|
|
||||||
|
|
||||||
for calls, operation in self.assignment_details:
|
for calls, operation in self.assignment_details:
|
||||||
search_calls(calls)
|
search_calls(calls)
|
||||||
|
|||||||
Reference in New Issue
Block a user