From 5e5c010bfd6f337c5967009212441f5f1b613ae9 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 7 Sep 2025 17:11:43 +0100 Subject: [PATCH 1/4] Remove incorrect comments instead --- Doc/whatsnew/3.14.rst | 3 +-- Include/internal/pycore_unicodeobject.h | 1 - Misc/NEWS.d/3.14.0b1.rst | 4 ++-- Objects/unicodeobject.c | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 853882ebec58af..a4507a84e7ee9c 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1188,8 +1188,7 @@ Other language changes (Contributed by Tomasz Pytel in :gh:`132329`.) * The command-line option :option:`-c` now automatically dedents its code - argument before execution. The auto-dedentation behavior mirrors - :func:`textwrap.dedent`. + argument before execution. (Contributed by Jon Crall and Steven Sun in :gh:`103998`.) * Improve error message when an object supporting the synchronous diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 8dfcaedd5ef2e8..068b208292d301 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -258,7 +258,6 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping( int forward); /* Dedent a string. - Behaviour is expected to be an exact match of `textwrap.dedent`. Return a new reference on success, NULL with exception set on error. */ extern PyObject* _PyUnicode_Dedent(PyObject *unicode); diff --git a/Misc/NEWS.d/3.14.0b1.rst b/Misc/NEWS.d/3.14.0b1.rst index 5d03d429f9ee14..789f80453d6938 100644 --- a/Misc/NEWS.d/3.14.0b1.rst +++ b/Misc/NEWS.d/3.14.0b1.rst @@ -1881,8 +1881,8 @@ Improve error message when :exc:`TypeError` occurs during .. nonce: BS3uVt .. section: Core and Builtins -String arguments passed to "-c" are now automatically dedented as if by -:func:`textwrap.dedent`. This allows "python -c" invocations to be indented +String arguments passed to "-c" are now automatically dedented. +This allows "python -c" invocations to be indented in shell scripts without causing indentation errors. (Patch by Jon Crall and Steven Sun) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4c88e4c1fdca2e..2bfc4808e3aed3 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14389,7 +14389,6 @@ search_longest_common_leading_whitespace( } /* Dedent a string. - Behaviour is expected to be an exact match of `textwrap.dedent`. Return a new reference on success, NULL with exception set on error. */ PyObject * From adb788455cb32ba7fe4f4a566764e6ad1de333d9 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 7 Sep 2025 17:57:30 +0100 Subject: [PATCH 2/4] Review --- Doc/using/cmdline.rst | 3 ++- Doc/whatsnew/3.14.rst | 3 ++- Include/internal/pycore_unicodeobject.h | 1 + Misc/NEWS.d/3.14.0b1.rst | 1 + Objects/unicodeobject.c | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 448f2725e9a3db..f91f5b8f4c5a89 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -49,7 +49,7 @@ additional methods of invocation: appropriately named script from that directory. * When called with ``-c command``, it executes the Python statement(s) given as *command*. Here *command* may contain multiple statements separated by - newlines. Leading whitespace is significant in Python statements! + newlines. * When called with ``-m module-name``, the given module is located on the Python module path and executed as a script. @@ -75,6 +75,7 @@ source. .. versionchanged:: 3.14 *command* is automatically dedented before execution. + Only supports spaces and tabs and doesn't normalize empty lines. .. option:: -m diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a4507a84e7ee9c..7431af2b777150 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1188,7 +1188,8 @@ Other language changes (Contributed by Tomasz Pytel in :gh:`132329`.) * The command-line option :option:`-c` now automatically dedents its code - argument before execution. + argument before execution. Only supports spaces and tabs and doesn't + normalize empty lines. (Contributed by Jon Crall and Steven Sun in :gh:`103998`.) * Improve error message when an object supporting the synchronous diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 068b208292d301..e8c054a51641eb 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -258,6 +258,7 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping( int forward); /* Dedent a string. + Only supports spaces and tabs and doesn't normalize empty lines. Return a new reference on success, NULL with exception set on error. */ extern PyObject* _PyUnicode_Dedent(PyObject *unicode); diff --git a/Misc/NEWS.d/3.14.0b1.rst b/Misc/NEWS.d/3.14.0b1.rst index 789f80453d6938..e8d974efb63881 100644 --- a/Misc/NEWS.d/3.14.0b1.rst +++ b/Misc/NEWS.d/3.14.0b1.rst @@ -1882,6 +1882,7 @@ Improve error message when :exc:`TypeError` occurs during .. section: Core and Builtins String arguments passed to "-c" are now automatically dedented. +Only supports spaces and tabs and doesn't normalize empty lines. This allows "python -c" invocations to be indented in shell scripts without causing indentation errors. (Patch by Jon Crall and Steven Sun) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2bfc4808e3aed3..32729626502825 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14389,6 +14389,7 @@ search_longest_common_leading_whitespace( } /* Dedent a string. + Only supports spaces and tabs and doesn't normalize empty lines. Return a new reference on success, NULL with exception set on error. */ PyObject * From af2a037d75ab8dec95511e9d6e1d3009e7807a77 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sun, 7 Sep 2025 18:16:44 +0100 Subject: [PATCH 3/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/using/cmdline.rst | 3 ++- Doc/whatsnew/3.14.rst | 4 ++-- Misc/NEWS.d/3.14.0b1.rst | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index f91f5b8f4c5a89..b704a7580f6960 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -75,7 +75,8 @@ source. .. versionchanged:: 3.14 *command* is automatically dedented before execution. - Only supports spaces and tabs and doesn't normalize empty lines. + The auto-dedentation behavior only supports spaces and tabs, + and does not normalize empty lines. .. option:: -m diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 7431af2b777150..bbc95b3e1a2cc0 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1188,8 +1188,8 @@ Other language changes (Contributed by Tomasz Pytel in :gh:`132329`.) * The command-line option :option:`-c` now automatically dedents its code - argument before execution. Only supports spaces and tabs and doesn't - normalize empty lines. + argument before execution. The auto-dedentation behavior only + supports spaces and tabs and does not normalize empty lines. (Contributed by Jon Crall and Steven Sun in :gh:`103998`.) * Improve error message when an object supporting the synchronous diff --git a/Misc/NEWS.d/3.14.0b1.rst b/Misc/NEWS.d/3.14.0b1.rst index e8d974efb63881..5a4e0cc552a66b 100644 --- a/Misc/NEWS.d/3.14.0b1.rst +++ b/Misc/NEWS.d/3.14.0b1.rst @@ -1882,7 +1882,8 @@ Improve error message when :exc:`TypeError` occurs during .. section: Core and Builtins String arguments passed to "-c" are now automatically dedented. -Only supports spaces and tabs and doesn't normalize empty lines. +Only space-based and tab-based indentations are supported; +empty lines are also not normalized. This allows "python -c" invocations to be indented in shell scripts without causing indentation errors. (Patch by Jon Crall and Steven Sun) From 690516ebcafc3fc1c2ca0fce23db81c36bf70940 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 7 Sep 2025 18:25:54 +0100 Subject: [PATCH 4/4] Indent --- Doc/using/cmdline.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index b704a7580f6960..0512069a337135 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -75,8 +75,8 @@ source. .. versionchanged:: 3.14 *command* is automatically dedented before execution. - The auto-dedentation behavior only supports spaces and tabs, - and does not normalize empty lines. + The auto-dedentation behavior only supports spaces and tabs, + and does not normalize empty lines. .. option:: -m