From 230a7bc024752bc516f2e85cccb762bb7a208418 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 27 Jul 2016 23:48:04 +0200 Subject: [PATCH] Remove the recursion detection in imports, because it's not needed there anymore. --- jedi/evaluate/imports.py | 73 ++++++++++++++++++--------------------- jedi/evaluate/iterable.py | 11 +++--- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 9f5842bd..8fdd5b97 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -68,56 +68,49 @@ class ImportWrapper(tree.Base): @memoize_default() def follow(self, is_goto=False): - if self._evaluator.recursion_detector.push_stmt(self._import): - # check recursion - return set() - + module = self._evaluator.wrap(self._import.get_parent_until()) + import_path = self._import.path_for_name(self._name) + from_import_name = None try: - module = self._evaluator.wrap(self._import.get_parent_until()) - import_path = self._import.path_for_name(self._name) - from_import_name = None - try: - from_names = self._import.get_from_names() - except AttributeError: - # Is an import_name - pass - else: - if len(from_names) + 1 == len(import_path): - # We have to fetch the from_names part first and then check - # if from_names exists in the modules. - from_import_name = import_path[-1] - import_path = from_names + from_names = self._import.get_from_names() + except AttributeError: + # Is an import_name + pass + else: + if len(from_names) + 1 == len(import_path): + # We have to fetch the from_names part first and then check + # if from_names exists in the modules. + from_import_name = import_path[-1] + import_path = from_names - importer = Importer(self._evaluator, tuple(import_path), - module, self._import.level) + importer = Importer(self._evaluator, tuple(import_path), + module, self._import.level) - types = importer.follow() + types = importer.follow() - #if self._import.is_nested() and not self.nested_resolve: - # scopes = [NestedImportModule(module, self._import)] + #if self._import.is_nested() and not self.nested_resolve: + # scopes = [NestedImportModule(module, self._import)] - if from_import_name is not None: - types = set(chain.from_iterable( - self._evaluator.find_types(t, unicode(from_import_name), - is_goto=is_goto) - for t in types)) + if from_import_name is not None: + types = set(chain.from_iterable( + self._evaluator.find_types(t, unicode(from_import_name), + is_goto=is_goto) + for t in types)) - if not types: - path = import_path + [from_import_name] - importer = Importer(self._evaluator, tuple(path), - module, self._import.level) - types = importer.follow() - # goto only accepts `Name` - if is_goto: - types = set(s.name for s in types) - else: + if not types: + path = import_path + [from_import_name] + importer = Importer(self._evaluator, tuple(path), + module, self._import.level) + types = importer.follow() # goto only accepts `Name` if is_goto: types = set(s.name for s in types) + else: + # goto only accepts `Name` + if is_goto: + types = set(s.name for s in types) - debug.dbg('after import: %s', types) - finally: - self._evaluator.recursion_detector.pop_stmt() + debug.dbg('after import: %s', types) return types diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 8bcfdb28..acbd7b08 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -739,11 +739,12 @@ def _check_array_additions(evaluator, compare_array, module, is_list): # Check for recursion. Possible by using 'extend' in # combination with function calls. continue - if compare_array in evaluator.eval_element(power): - # The arrays match. Now add the results - added_types |= check_additions(execution_trailer.children[1], add_name) - - evaluator.recursion_detector.pop_stmt() + try: + if compare_array in evaluator.eval_element(power): + # The arrays match. Now add the results + added_types |= check_additions(execution_trailer.children[1], add_name) + finally: + evaluator.recursion_detector.pop_stmt() # reset settings settings.dynamic_params_for_other_modules = temp_param_add debug.dbg('Dynamic array result %s' % added_types, color='MAGENTA')