diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index b4d6d25871bcf4..193464f266cf84 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -1456,10 +1456,10 @@ def newline_and_indent_event(self, event): c = y.get_continuation_type() if c != pyparse.C_NONE: # The current statement hasn't ended yet. - if c == pyparse.C_STRING_FIRST_LINE: - # After the first line of a string do not indent at all. - pass - elif c == pyparse.C_STRING_NEXT_LINES: + if ( + c == pyparse.C_STRING_FIRST_LINE + or c == pyparse.C_STRING_NEXT_LINES + ): # Inside a string which started before this line; # just mimic the current indent. text.insert("insert", indent, self.user_input_insert_tags) diff --git a/Lib/idlelib/idle_test/test_editor.py b/Lib/idlelib/idle_test/test_editor.py index 0dfe2f3c58befa..fa0eeca0c09603 100644 --- a/Lib/idlelib/idle_test/test_editor.py +++ b/Lib/idlelib/idle_test/test_editor.py @@ -140,9 +140,9 @@ def test_indent_and_newline_event(self): ' def f1(self, a, b):', ' def f1(self,\n a, b):\n', '1.15'), - TestInfo('Inside string with one line - no indent.', + TestInfo('Inside string with one line.', ' """Docstring."""', - ' """Docstring.\n"""\n', + ' """Docstring.\n """\n', '1.15'), TestInfo('Inside string with more than one line.', ' """Docstring.\n Docstring Line 2"""', diff --git a/Misc/NEWS.d/next/IDLE/2025-09-06-06-01-45.gh-issue-138539.jBvls0.rst b/Misc/NEWS.d/next/IDLE/2025-09-06-06-01-45.gh-issue-138539.jBvls0.rst new file mode 100644 index 00000000000000..b83c5669207311 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2025-09-06-06-01-45.gh-issue-138539.jBvls0.rst @@ -0,0 +1 @@ +Fix wrong indent for docstrings