forked from VimPlug/jedi
Trying to move towards unifying goto and py__getattribute__
This commit is contained in:
@@ -76,27 +76,24 @@ class HelperValueMixin(object):
|
|||||||
"""
|
"""
|
||||||
if name_context is None:
|
if name_context is None:
|
||||||
name_context = self
|
name_context = self
|
||||||
from jedi.inference import finder
|
names, f = self._goto(name_or_str, name_context, analysis_errors)
|
||||||
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
|
values = f.find(names, attribute_lookup=True)
|
||||||
position, analysis_errors=analysis_errors)
|
|
||||||
filters = self._get_value_filters(name_or_str)
|
|
||||||
values = f.find(filters, attribute_lookup=True)
|
|
||||||
if not values:
|
if not values:
|
||||||
n = name_or_str.value if isinstance(name_or_str, Name) else name_or_str
|
n = name_or_str.value if isinstance(name_or_str, Name) else name_or_str
|
||||||
values = self.py__getattribute__alternatives(n)
|
values = self.py__getattribute__alternatives(n)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def goto(self, name_or_str, name_context=None, analysis_errors=True):
|
def goto(self, *args, **kwargs):
|
||||||
"""
|
return self._goto(*args, **kwargs)[0]
|
||||||
:param position: Position of the last statement -> tuple of line, column
|
|
||||||
"""
|
def _goto(self, name_or_str, name_context=None, analysis_errors=True):
|
||||||
if name_context is None:
|
if name_context is None:
|
||||||
name_context = self
|
name_context = self
|
||||||
from jedi.inference import finder
|
from jedi.inference import finder
|
||||||
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
|
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
|
||||||
analysis_errors=analysis_errors)
|
analysis_errors=analysis_errors)
|
||||||
filters = self._get_value_filters(name_or_str)
|
filters = self._get_value_filters(name_or_str)
|
||||||
return f.filter_name(filters)
|
return f.filter_name(filters), f
|
||||||
|
|
||||||
def py__await__(self):
|
def py__await__(self):
|
||||||
await_value_set = self.py__getattribute__(u"__await__")
|
await_value_set = self.py__getattribute__(u"__await__")
|
||||||
|
|||||||
@@ -20,12 +20,15 @@ class AbstractContext(object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def goto(self, name_or_str, position):
|
def goto(self, name_or_str, position):
|
||||||
|
return self._goto(name_or_str, position)[0]
|
||||||
|
|
||||||
|
def _goto(self, name_or_str, position):
|
||||||
from jedi.inference import finder
|
from jedi.inference import finder
|
||||||
f = finder.NameFinder(self.inference_state, self, self, name_or_str, position)
|
f = finder.NameFinder(self.inference_state, self, self, name_or_str, position)
|
||||||
filters = _get_global_filters_for_name(
|
filters = _get_global_filters_for_name(
|
||||||
self, name_or_str if isinstance(name_or_str, Name) else None, position,
|
self, name_or_str if isinstance(name_or_str, Name) else None, position,
|
||||||
)
|
)
|
||||||
return f.filter_name(filters)
|
return f.filter_name(filters), f
|
||||||
|
|
||||||
def py__getattribute__(self, name_or_str, name_value=None, position=None,
|
def py__getattribute__(self, name_or_str, name_value=None, position=None,
|
||||||
analysis_errors=True):
|
analysis_errors=True):
|
||||||
@@ -34,13 +37,8 @@ class AbstractContext(object):
|
|||||||
"""
|
"""
|
||||||
if name_value is None:
|
if name_value is None:
|
||||||
name_value = self
|
name_value = self
|
||||||
from jedi.inference import finder
|
names, f = self._goto(name_or_str, position)
|
||||||
f = finder.NameFinder(self.inference_state, self, name_value, name_or_str,
|
return f.find(names, attribute_lookup=False)
|
||||||
position, analysis_errors=analysis_errors)
|
|
||||||
filters = _get_global_filters_for_name(
|
|
||||||
self, name_or_str if isinstance(name_or_str, Name) else None, position,
|
|
||||||
)
|
|
||||||
return f.find(filters, attribute_lookup=False)
|
|
||||||
|
|
||||||
def get_root_context(self):
|
def get_root_context(self):
|
||||||
parent_context = self.parent_context
|
parent_context = self.parent_context
|
||||||
|
|||||||
@@ -46,12 +46,11 @@ class NameFinder(object):
|
|||||||
self._found_predefined_types = None
|
self._found_predefined_types = None
|
||||||
self._analysis_errors = analysis_errors
|
self._analysis_errors = analysis_errors
|
||||||
|
|
||||||
def find(self, filters, attribute_lookup):
|
def find(self, names, attribute_lookup):
|
||||||
"""
|
"""
|
||||||
:params bool attribute_lookup: Tell to logic if we're accessing the
|
:params bool attribute_lookup: Tell to logic if we're accessing the
|
||||||
attribute or the contents of e.g. a function.
|
attribute or the contents of e.g. a function.
|
||||||
"""
|
"""
|
||||||
names = self.filter_name(filters)
|
|
||||||
if self._found_predefined_types is not None and names:
|
if self._found_predefined_types is not None and names:
|
||||||
check = flow_analysis.reachability_check(
|
check = flow_analysis.reachability_check(
|
||||||
context=self._context,
|
context=self._context,
|
||||||
@@ -63,7 +62,10 @@ class NameFinder(object):
|
|||||||
return self._found_predefined_types
|
return self._found_predefined_types
|
||||||
|
|
||||||
types = self._names_to_types(names)
|
types = self._names_to_types(names)
|
||||||
|
self.check_issues(names, types, attribute_lookup)
|
||||||
|
return types
|
||||||
|
|
||||||
|
def check_issues(self, names, types, attribute_lookup):
|
||||||
if not names and self._analysis_errors and not types \
|
if not names and self._analysis_errors and not types \
|
||||||
and not (isinstance(self._name, tree.Name) and
|
and not (isinstance(self._name, tree.Name) and
|
||||||
isinstance(self._name.parent.parent, tree.Param)):
|
isinstance(self._name.parent.parent, tree.Param)):
|
||||||
@@ -76,8 +78,6 @@ class NameFinder(object):
|
|||||||
% self._string_name)
|
% self._string_name)
|
||||||
analysis.add(self._name_context, 'name-error', self._name, message)
|
analysis.add(self._name_context, 'name-error', self._name, message)
|
||||||
|
|
||||||
return types
|
|
||||||
|
|
||||||
def filter_name(self, filters):
|
def filter_name(self, filters):
|
||||||
"""
|
"""
|
||||||
Searches names that are defined in a scope (the different
|
Searches names that are defined in a scope (the different
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ def tree_name_to_values(inference_state, context, tree_name):
|
|||||||
# For global_stmt lookups, we only need the first possible scope,
|
# For global_stmt lookups, we only need the first possible scope,
|
||||||
# which means the function itself.
|
# which means the function itself.
|
||||||
filters = [next(c.get_filters())]
|
filters = [next(c.get_filters())]
|
||||||
return finder.find(filters, attribute_lookup=False)
|
return finder.find(finder.filter_name(filters), attribute_lookup=False)
|
||||||
elif node.type not in ('import_from', 'import_name'):
|
elif node.type not in ('import_from', 'import_name'):
|
||||||
c = context.create_context(tree_name)
|
c = context.create_context(tree_name)
|
||||||
return infer_atom(c, tree_name)
|
return infer_atom(c, tree_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user