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