diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py index ec3e0be93be..966297b6ab6 100644 --- a/spyder/plugins/editor/widgets/codeeditor.py +++ b/spyder/plugins/editor/widgets/codeeditor.py @@ -2833,10 +2833,12 @@ def paste(self): preceding_text) # Make sure the code is not flattened - max_dedent = min( - [self.get_line_indentation(line) - for line in remaining_lines if line.strip() != ""]) - lines_adjustment = max(lines_adjustment, -max_dedent) + indentations = [ + self.get_line_indentation(line) + for line in remaining_lines if line.strip() != ""] + if indentations: + max_dedent = min(indentations) + lines_adjustment = max(lines_adjustment, -max_dedent) # Get new text remaining_lines = [