diff --git a/jedi/api/refactoring/extract.py b/jedi/api/refactoring/extract.py index fbc024bb..e6e1c6b9 100644 --- a/jedi/api/refactoring/extract.py +++ b/jedi/api/refactoring/extract.py @@ -297,11 +297,11 @@ def _check_for_non_extractables(nodes): try: children = n.children except AttributeError: - if n.value in ('return', 'yield'): + if n.value == 'return': raise RefactoringError( - 'Can only extract %s statements if they are at the end.' - % n.value - ) + 'Can only extract return statements if they are at the end.') + if n.value == 'yield': + raise RefactoringError('Cannot extract yield statements.') else: _check_for_non_extractables(children) diff --git a/test/refactor/extract_function.py b/test/refactor/extract_function.py index 809b913d..0fab0b52 100644 --- a/test/refactor/extract_function.py +++ b/test/refactor/extract_function.py @@ -419,7 +419,7 @@ def x(): return pass # ++++++++++++++++++++++++++++++++++++++++++++++++++ -Can only extract yield statements if they are at the end. +Cannot extract yield statements. # -------------------------------------------------- random-yield-2 def x(): #? 0 error {'new_name': 'ab', 'until_line': 4, 'until_column': 10} @@ -429,4 +429,4 @@ def x(): finally: pass # ++++++++++++++++++++++++++++++++++++++++++++++++++ -Can only extract yield statements if they are at the end. +Cannot extract yield statements.