mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 22:55:43 +08:00
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
|
||||
# complicated.
|
||||
sub = self._get_method_execution(sub)
|
||||
print(sub.get_names_dict())
|
||||
for n in sub.get_defined_names():
|
||||
# Only names with the selfname are being added.
|
||||
# It is also important, that they have a len() of 2,
|
||||
@@ -579,6 +580,10 @@ class FunctionExecution(Executed):
|
||||
break
|
||||
return types
|
||||
|
||||
@underscore_memoization
|
||||
def get_names_dict(self):
|
||||
return self.
|
||||
|
||||
@memoize_default(default=())
|
||||
def _get_params(self):
|
||||
"""
|
||||
@@ -631,7 +636,7 @@ class FunctionExecution(Executed):
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def returns(self):
|
||||
return self._copy_list('returns')
|
||||
return self._copy_list(self)
|
||||
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
|
||||
@@ -100,6 +100,9 @@ class Parser(object):
|
||||
except KeyError:
|
||||
self.module.used_names[tok_name] = set([simple])
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -244,7 +244,7 @@ class Scope(Simple, DocstringMixin):
|
||||
:type start_pos: tuple(int, int)
|
||||
"""
|
||||
__slots__ = ('subscopes', 'imports', 'statements', '_doc_token', 'asserts',
|
||||
'returns', 'is_generator')
|
||||
'returns', 'is_generator', '_names_dict')
|
||||
|
||||
def __init__(self, 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
|
||||
# returns will be in "normal" modules.
|
||||
self.returns = []
|
||||
self._names_dict = defaultdict(lambda: [])
|
||||
self.is_generator = False
|
||||
|
||||
def is_scope(self):
|
||||
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):
|
||||
sub.parent = self.use_as_parent
|
||||
sub.decorators = decorators
|
||||
@@ -672,6 +680,10 @@ class Flow(Scope):
|
||||
s.parent = self.use_as_parent
|
||||
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
|
||||
def parent(self):
|
||||
return self._parent
|
||||
@@ -996,12 +1008,11 @@ class Statement(Simple, DocstringMixin):
|
||||
c = call
|
||||
# Check if there's an execution in it, if so this is
|
||||
# not a set_var.
|
||||
while c:
|
||||
if isinstance(c.next, Array):
|
||||
while True:
|
||||
if c.next is None or isinstance(c.next, Array):
|
||||
break
|
||||
c = c.next
|
||||
else:
|
||||
dct[unicode(c.name)] = call
|
||||
dct[unicode(c.name)] = call
|
||||
|
||||
for calls, operation in self.assignment_details:
|
||||
search_calls(calls)
|
||||
|
||||
Reference in New Issue
Block a user