From 13c2279feac6bbf8d1024779d951b45384a1d27a Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 12 Nov 2014 13:48:08 +0100 Subject: [PATCH] Make Generator tuple assignments work. --- jedi/evaluate/iterable.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index ed2e86ec..26cdc64d 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -58,6 +58,19 @@ class GeneratorMixin(object): def scope_names_generator(self, position=None): yield self, self._get_defined_names() + def get_index_types(self, evaluator, index_array): + #debug.warning('Tried to get array access on a generator: %s', self) + analysis.add(self._evaluator, 'type-error-generator', index_array) + return [] + + def get_exact_index_types(self, index): + """ + Exact lookups are used for tuple lookups, which are perfectly fine if + used with generators. + """ + return [self.iter_content()[index]] + + class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)): """Handling of `yield` functions.""" @@ -74,18 +87,6 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)) from jedi.evaluate.representation import FunctionExecution return FunctionExecution(self._evaluator, self.func, self.var_args).get_return_types() - def get_index_types(self, index_array): - #debug.warning('Tried to get array access on a generator: %s', self) - analysis.add(self._evaluator, 'type-error-generator', index_array) - return [] - - def get_exact_index_types(self, index): - """ - Exact lookups are used for tuple lookups, which are perfectly fine if - used with generators. - """ - return [self.iter_content()[index]] - def __getattr__(self, name): if name not in ['start_pos', 'end_pos', 'parent', 'get_imports', 'asserts', 'doc', 'docstr', 'get_parent_until', @@ -157,7 +158,7 @@ class ListComprehension(Comprehension): class GeneratorComprehension(Comprehension, GeneratorMixin): def iter_content(self): - return self._evaluator.eval_statement_element(self.comprehension) + return self._evaluator.eval_element(self.eval_node()) class Array(IterableWrapper):