diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 448f2725e9a3db..0512069a337135 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,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. .. option:: -m diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 853882ebec58af..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. The auto-dedentation behavior mirrors - :func:`textwrap.dedent`. + 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/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 8dfcaedd5ef2e8..e8c054a51641eb 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -258,7 +258,7 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping( int forward); /* Dedent a string. - Behaviour is expected to be an exact match of `textwrap.dedent`. + 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 5d03d429f9ee14..5a4e0cc552a66b 100644 --- a/Misc/NEWS.d/3.14.0b1.rst +++ b/Misc/NEWS.d/3.14.0b1.rst @@ -1881,8 +1881,10 @@ 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. +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) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4c88e4c1fdca2e..32729626502825 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14389,7 +14389,7 @@ search_longest_common_leading_whitespace( } /* Dedent a string. - Behaviour is expected to be an exact match of `textwrap.dedent`. + Only supports spaces and tabs and doesn't normalize empty lines. Return a new reference on success, NULL with exception set on error. */ PyObject *