diff --git a/jedi/inference/base_value.py b/jedi/inference/base_value.py index 8384f95e..0619a7c4 100644 --- a/jedi/inference/base_value.py +++ b/jedi/inference/base_value.py @@ -8,7 +8,7 @@ just one. """ from functools import reduce 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._compatibility import zip_longest, unicode @@ -81,6 +81,14 @@ class HelperValueMixin(object): if not values: n = name_or_str.value if isinstance(name_or_str, Name) else name_or_str 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 def goto(self, *args, **kwargs): diff --git a/jedi/inference/context.py b/jedi/inference/context.py index fd66b6bf..5c4b097d 100644 --- a/jedi/inference/context.py +++ b/jedi/inference/context.py @@ -1,7 +1,7 @@ from abc import abstractmethod 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, \ GlobalNameFilter @@ -30,15 +30,24 @@ class AbstractContext(object): ) 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): """ :param position: Position of the last statement -> tuple of line, column """ - if name_value is None: - name_value = self + if name_context is None: + name_context = self 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): parent_context = self.parent_context diff --git a/jedi/inference/finder.py b/jedi/inference/finder.py index 1082216a..cd4b8f6c 100644 --- a/jedi/inference/finder.py +++ b/jedi/inference/finder.py @@ -77,22 +77,7 @@ class NameFinder(object): return NO_VALUES return found_predefined_types - 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 \ - 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) + return self._names_to_types(names) def filter_name(self, filters): """