diff --git a/jedi/evaluate/compiled/fake/_functools.pym b/jedi/evaluate/compiled/fake/_functools.pym index be8470f0..235e80a1 100644 --- a/jedi/evaluate/compiled/fake/_functools.pym +++ b/jedi/evaluate/compiled/fake/_functools.pym @@ -5,5 +5,5 @@ class partial(): self.__keywords = keywords def __call__(self, *args, **kwargs): - # I know this doesn't work in Python, but Jedi can this ;-) + # I know this doesn't work in Python, but in Jedi it does ;-) return self.__func(*self.__args, *args, **self.keywords, **kwargs) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 9adce012..86561c12 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -444,7 +444,7 @@ class FunctionExecution(Executable): if func.is_generator and not evaluate_generator: return [iterable.Generator(self._evaluator, func, self.var_args)] else: - stmts = docstrings.find_return_types(self._evaluator, func) + stmts = list(docstrings.find_return_types(self._evaluator, func)) for r in self.returns: if r is not None: stmts += self._evaluator.eval_statement(r) diff --git a/test/test_evaluate/test_representation.py b/test/test_evaluate/test_representation.py new file mode 100644 index 00000000..8d6dd91e --- /dev/null +++ b/test/test_evaluate/test_representation.py @@ -0,0 +1,20 @@ +from jedi import Script + + +def test_function_execution(): + """ + We've been having an issue of a mutable list that was changed inside the + function execution. Test if an execution always returns the same result. + """ + + s = """ + def x(): + return str() + x""" + d = Script(s).goto_definitions()[0] + # Now just use the internals of the result (easiest way to get a fully + # usable function). + func, evaluator = d._definition, d._evaluator + # Should return the same result both times. + assert len(evaluator.execute(func)) == 1 + assert len(evaluator.execute(func)) == 1