1
0
forked from VimPlug/jedi

Move error handling for py__getattribute__

This commit is contained in:
Dave Halter
2019-08-24 00:59:48 +02:00
parent bd24ee2ab3
commit ddb2ccb657
3 changed files with 24 additions and 22 deletions

View File

@@ -8,7 +8,7 @@ just one.
""" """
from functools import reduce from functools import reduce
from operator import add from operator import add
from parso.python.tree import ExprStmt, SyncCompFor, Name from parso.python.tree import ExprStmt, SyncCompFor, Name, Param
from jedi import debug from jedi import debug
from jedi._compatibility import zip_longest, unicode from jedi._compatibility import zip_longest, unicode
@@ -81,6 +81,14 @@ class HelperValueMixin(object):
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)
if not names and analysis_errors and not values \
and not (isinstance(name_or_str, Name) and
isinstance(name_or_str.parent.parent, Param)):
if isinstance(name_or_str, Name):
from jedi.inference import analysis
analysis.add_attribute_error(
name_context, self, name_or_str)
return values return values
def goto(self, *args, **kwargs): def goto(self, *args, **kwargs):

View File

@@ -1,7 +1,7 @@
from abc import abstractmethod from abc import abstractmethod
from parso.tree import search_ancestor from parso.tree import search_ancestor
from parso.python.tree import Name from parso.python.tree import Name, Param
from jedi.inference.filters import ParserTreeFilter, MergedFilter, \ from jedi.inference.filters import ParserTreeFilter, MergedFilter, \
GlobalNameFilter GlobalNameFilter
@@ -30,15 +30,24 @@ class AbstractContext(object):
) )
return f.filter_name(filters), f 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_context=None, position=None,
analysis_errors=True): analysis_errors=True):
""" """
:param position: Position of the last statement -> tuple of line, column :param position: Position of the last statement -> tuple of line, column
""" """
if name_value is None: if name_context is None:
name_value = self name_context = self
names, f = self._goto(name_or_str, position) names, f = self._goto(name_or_str, position)
return f.find(names, attribute_lookup=False) values = f.find(names, attribute_lookup=False)
if not names and analysis_errors and not values \
and not (isinstance(name_or_str, Name) and
isinstance(name_or_str.parent.parent, Param)):
if isinstance(name_or_str, Name):
from jedi.inference import analysis
message = ("NameError: name '%s' is not defined."
% name_or_str if isinstance(name_or_str, Name) else name_or_str)
analysis.add(name_context, 'name-error', name_or_str, message)
return values
def get_root_context(self): def get_root_context(self):
parent_context = self.parent_context parent_context = self.parent_context

View File

@@ -77,22 +77,7 @@ class NameFinder(object):
return NO_VALUES return NO_VALUES
return found_predefined_types return found_predefined_types
types = self._names_to_types(names) return 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 \
and not (isinstance(self._name, tree.Name) and
isinstance(self._name.parent.parent, tree.Param)):
if isinstance(self._name, tree.Name):
if attribute_lookup:
analysis.add_attribute_error(
self._name_context, self._context, self._name)
else:
message = ("NameError: name '%s' is not defined."
% self._string_name)
analysis.add(self._name_context, 'name-error', self._name, message)
def filter_name(self, filters): def filter_name(self, filters):
""" """