mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-22 21:31:26 +08:00
more consequent usage of scope_names_generator
This commit is contained in:
@@ -73,6 +73,7 @@ import itertools
|
||||
from jedi._compatibility import next, hasattr, unicode
|
||||
from jedi.parser import representation as pr
|
||||
from jedi.parser.tokenize import Token
|
||||
from jedi.parser import fast
|
||||
from jedi import debug
|
||||
from jedi.evaluate import representation as er
|
||||
from jedi.evaluate import imports
|
||||
@@ -136,7 +137,10 @@ class Evaluator(object):
|
||||
# `=` is always the last character in aug assignments -> -1
|
||||
operator = operator[:-1]
|
||||
name = str(expr_list[0].name)
|
||||
left = self.find_types(stmt.parent, name, stmt.start_pos)
|
||||
parent = stmt.parent
|
||||
if isinstance(parent, (pr.SubModule, fast.Module)):
|
||||
parent = er.ModuleWrapper(self, parent)
|
||||
left = self.find_types(parent, name, stmt.start_pos)
|
||||
if isinstance(stmt.parent, pr.ForFlow):
|
||||
# iterate through result and add the values, that's possible
|
||||
# only in for loops without clutter, because they are
|
||||
|
||||
@@ -67,8 +67,6 @@ class NameFinder(object):
|
||||
return get_names_of_scope(self._evaluator, self.scope, self.position)
|
||||
else:
|
||||
try:
|
||||
# Use scope generators if parts of it (e.g. sub classes or star
|
||||
# imports).
|
||||
gen = self.scope.scope_names_generator
|
||||
except AttributeError:
|
||||
if isinstance(self.scope, er.Class):
|
||||
@@ -79,7 +77,7 @@ class NameFinder(object):
|
||||
names = _get_defined_names_for_position(self.scope, self.position)
|
||||
return iter([(self.scope, names)])
|
||||
else:
|
||||
return gen()
|
||||
return gen(self.position)
|
||||
|
||||
def filter_name(self, scope_names_generator):
|
||||
"""
|
||||
|
||||
@@ -57,7 +57,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
else:
|
||||
yield name
|
||||
|
||||
def scope_names_generator(self):
|
||||
def scope_names_generator(self, position=None):
|
||||
yield self, self._get_defined_names()
|
||||
|
||||
def iter_content(self):
|
||||
@@ -175,7 +175,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
values = [self._array.values[index]]
|
||||
return _follow_values(self._evaluator, values)
|
||||
|
||||
def scope_names_generator(self):
|
||||
def scope_names_generator(self, position=None):
|
||||
"""
|
||||
This method generates all `ArrayMethod` for one pr.Array.
|
||||
It returns e.g. for a list: append, pop, ...
|
||||
|
||||
@@ -549,14 +549,14 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module)):
|
||||
self._module = module
|
||||
|
||||
def scope_names_generator(self, position=None):
|
||||
yield self, pr.filter_after_position(self.get_defined_names(), position)
|
||||
yield self, self.module_attributes()
|
||||
yield self, pr.filter_after_position(self._module.get_defined_names(), position)
|
||||
yield self, self._module_attributes()
|
||||
sub_modules = self._sub_modules()
|
||||
if sub_modules:
|
||||
yield self, self._sub_modules()
|
||||
|
||||
@memoize_default()
|
||||
def module_attributes(self):
|
||||
def _module_attributes(self):
|
||||
names = ['__file__', '__package__', '__doc__', '__name__', '__version__']
|
||||
# All the additional module attributes are strings.
|
||||
parent = Instance(self._evaluator, compiled.create(self._evaluator, str))
|
||||
|
||||
Reference in New Issue
Block a user