From 499343c44b3fa35342b1b2021a423e026aa05fc6 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 7 Jul 2025 12:30:56 +0300 Subject: [PATCH 1/6] gh-136355: Deprecate `-b` and `-bb` CLI flags in 3.15 --- Doc/using/cmdline.rst | 10 ++++++++ Doc/whatsnew/3.15.rst | 12 +++++++++ Lib/test/test_cmd_line.py | 25 +++++++++++++++++-- ...-07-07-12-24-00.gh-issue-136355.MTcA8j.rst | 2 ++ Python/initconfig.c | 6 +++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index cad49e2deeb46f..22cad9ea5780dc 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -254,6 +254,16 @@ Miscellaneous options .. versionchanged:: 3.5 Affects also comparisons of :class:`bytes` with :class:`int`. + .. deprecated-removed:: 3.15 3.17 + + Deprecate :option:`-b` and :option:`-bb` + and schedule them for removal in Python 3.17. + They were mainly a transition helpers for Python2 -> Python3 era. + In 3.17 no :exc:`BytesWarning` won't be raised for these cases. + If you want to check for the same things in the future, + use any type-checker of your choice. + + .. option:: -B If given, Python won't try to write ``.pyc`` files on the diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 706a816f888b30..58b9509bcd55dd 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -206,6 +206,18 @@ module_name Deprecated ========== +CLI +--- + +* Deprecate :option:`-b` and :option:`!-bb` + and schedule them for removal in Python 3.17. + They were mainly a transition helpers for Python2 -> Python3 era. + In 3.17 no :exc:`BytesWarning` won't be raised for these cases. + If you want to check for the same things in the future, + use any type-checker of your choice. + + (Contributed by Nikita Sobolev in :gh:`136355`.) + hashlib ------- diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index c17d749d4a17ed..caec8b7ccf9e65 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -32,6 +32,12 @@ def _kill_python_and_exit_code(p): return data, returncode +b_deprecation_msg = ( + '-b option is deprecated since Python 3.15 ' + 'and will be removed in Python 3.17' +) + + class CmdLineTest(unittest.TestCase): def test_directories(self): assert_python_failure('.') @@ -706,7 +712,7 @@ def run_xdev(self, *args, check_exitcode=True, xdev=True): env=env) if check_exitcode: self.assertEqual(proc.returncode, 0, proc) - return proc.stdout.rstrip() + return self.maybe_remove_b_deprecation_msg(proc.stdout) @support.cpython_only def test_xdev(self): @@ -789,7 +795,22 @@ def check_warnings_filters(self, cmdline_option, envvar, use_pywarning=False): universal_newlines=True, env=env) self.assertEqual(proc.returncode, 0, proc) - return proc.stdout.rstrip() + return self.maybe_remove_b_deprecation_msg(proc.stdout) + + def maybe_remove_b_deprecation_msg(self, output): + return output.replace(b_deprecation_msg + '\n', '').rstrip() + + def test_b_deprecation_msg_stderr(self): + for arg in ['-b', '-bb']: + with self.subTest(arg=arg): + args = (sys.executable, arg, '-c', '') + proc = subprocess.run(args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + self.assertEqual(proc.returncode, 0, proc) + self.assertEqual(proc.stdout, '') + self.assertEqual(proc.stderr.rstrip(), b_deprecation_msg) def test_warnings_filter_precedence(self): expected_filters = ("error::BytesWarning " diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst new file mode 100644 index 00000000000000..47c34840063abb --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst @@ -0,0 +1,2 @@ +Deprecate :option:`-b` and :option:`!-bb` and schedule them +for removal in the future versions of Python. diff --git a/Python/initconfig.c b/Python/initconfig.c index 71d7cfed5c44c1..093444a506681d 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -256,6 +256,7 @@ static const char usage_help[] = "\ Options (and corresponding environment variables):\n\ -b : issue warnings about converting bytes/bytearray to str and comparing\n\ bytes/bytearray with str or bytes with int. (-bb: issue errors)\n\ + deprecated since 3.15 and will be removed in 3.17\n\ -B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x\n\ -c cmd : program passed in as string (terminates option list)\n\ -d : turn on parser debugging output (for experts only, only works on\n\ @@ -2944,6 +2945,11 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, return _PyStatus_EXIT(0); case 'b': + if (!config->bytes_warning) { + fprintf(stderr, + "-b option is deprecated since Python 3.15 " + "and will be removed in Python 3.17\n"); + } config->bytes_warning++; break; From 2c83cfccc3daf373114d0781bc0fe2130013b4a5 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 10 Sep 2025 19:04:15 +0300 Subject: [PATCH 2/6] No warning, no plans to remove `-b` and `-bb`, only make them no-op --- Doc/c-api/init_config.rst | 4 +++ Doc/using/cmdline.rst | 11 ++++---- Doc/whatsnew/3.15.rst | 9 +++---- Lib/test/test_cmd_line.py | 25 ++----------------- ...-07-07-12-24-00.gh-issue-136355.MTcA8j.rst | 2 +- Python/initconfig.c | 7 +----- 6 files changed, 17 insertions(+), 41 deletions(-) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 4fd10224262488..9df847edc451b7 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1280,6 +1280,10 @@ PyConfig Default: ``0``. + .. deprecated:: 3.15 + + Deprecated, will become no-op in 3.17. + .. c:member:: int warn_default_encoding If non-zero, emit a :exc:`EncodingWarning` warning when :class:`io.TextIOWrapper` diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 22cad9ea5780dc..b36ccb20103b7a 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -256,12 +256,11 @@ Miscellaneous options .. deprecated-removed:: 3.15 3.17 - Deprecate :option:`-b` and :option:`-bb` - and schedule them for removal in Python 3.17. - They were mainly a transition helpers for Python2 -> Python3 era. - In 3.17 no :exc:`BytesWarning` won't be raised for these cases. - If you want to check for the same things in the future, - use any type-checker of your choice. + Deprecate :option:`-b` and :option:`!-bb` + and schedule them to become no-op in Python 3.17. + These were primarily helpers for the Python 2 -> 3 transition. + Starting with Python 3.17, no :exc:`BytesWarning` will be raised + for these cases; use a type checker instead. .. option:: -B diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 58b9509bcd55dd..5f91d229a3ead8 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -210,11 +210,10 @@ CLI --- * Deprecate :option:`-b` and :option:`!-bb` - and schedule them for removal in Python 3.17. - They were mainly a transition helpers for Python2 -> Python3 era. - In 3.17 no :exc:`BytesWarning` won't be raised for these cases. - If you want to check for the same things in the future, - use any type-checker of your choice. + and schedule them to become no-op in Python 3.17. + These were primarily helpers for the Python 2 -> 3 transition. + Starting with Python 3.17, no :exc:`BytesWarning` will be raised + for these cases; use a type checker instead. (Contributed by Nikita Sobolev in :gh:`136355`.) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index caec8b7ccf9e65..c17d749d4a17ed 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -32,12 +32,6 @@ def _kill_python_and_exit_code(p): return data, returncode -b_deprecation_msg = ( - '-b option is deprecated since Python 3.15 ' - 'and will be removed in Python 3.17' -) - - class CmdLineTest(unittest.TestCase): def test_directories(self): assert_python_failure('.') @@ -712,7 +706,7 @@ def run_xdev(self, *args, check_exitcode=True, xdev=True): env=env) if check_exitcode: self.assertEqual(proc.returncode, 0, proc) - return self.maybe_remove_b_deprecation_msg(proc.stdout) + return proc.stdout.rstrip() @support.cpython_only def test_xdev(self): @@ -795,22 +789,7 @@ def check_warnings_filters(self, cmdline_option, envvar, use_pywarning=False): universal_newlines=True, env=env) self.assertEqual(proc.returncode, 0, proc) - return self.maybe_remove_b_deprecation_msg(proc.stdout) - - def maybe_remove_b_deprecation_msg(self, output): - return output.replace(b_deprecation_msg + '\n', '').rstrip() - - def test_b_deprecation_msg_stderr(self): - for arg in ['-b', '-bb']: - with self.subTest(arg=arg): - args = (sys.executable, arg, '-c', '') - proc = subprocess.run(args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True) - self.assertEqual(proc.returncode, 0, proc) - self.assertEqual(proc.stdout, '') - self.assertEqual(proc.stderr.rstrip(), b_deprecation_msg) + return proc.stdout.rstrip() def test_warnings_filter_precedence(self): expected_filters = ("error::BytesWarning " diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst index 47c34840063abb..055126ed1981b0 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst @@ -1,2 +1,2 @@ Deprecate :option:`-b` and :option:`!-bb` and schedule them -for removal in the future versions of Python. +to become no-op in Python 3.17. diff --git a/Python/initconfig.c b/Python/initconfig.c index 093444a506681d..5e39821868fb01 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -256,7 +256,7 @@ static const char usage_help[] = "\ Options (and corresponding environment variables):\n\ -b : issue warnings about converting bytes/bytearray to str and comparing\n\ bytes/bytearray with str or bytes with int. (-bb: issue errors)\n\ - deprecated since 3.15 and will be removed in 3.17\n\ + deprecated since 3.15 and will become no-op in 3.17.\n\ -B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x\n\ -c cmd : program passed in as string (terminates option list)\n\ -d : turn on parser debugging output (for experts only, only works on\n\ @@ -2945,11 +2945,6 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, return _PyStatus_EXIT(0); case 'b': - if (!config->bytes_warning) { - fprintf(stderr, - "-b option is deprecated since Python 3.15 " - "and will be removed in Python 3.17\n"); - } config->bytes_warning++; break; From 37efb67d98a1f96a24861c8d645a1e899fb15ce6 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 11 Sep 2025 15:33:39 +0300 Subject: [PATCH 3/6] Address review --- Doc/c-api/init_config.rst | 5 +++-- Doc/using/cmdline.rst | 4 ++-- Doc/whatsnew/3.15.rst | 6 +++++- .../2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst | 7 +++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index f92c7e105fc750..9d9199f708af90 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1278,9 +1278,10 @@ PyConfig Default: ``0``. - .. deprecated:: 3.15 + .. deprecated-removed:: 3.15 3.17 - Deprecated, will become no-op in 3.17. + Deprecated, :option:`-b` and :option:`!-bb` will become no-op in 3.17. + :c:member:`~PyConfig.bytes_warning` will be removed in 3.17. .. c:member:: int warn_default_encoding diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 0f6e7c9ded1e22..3f8b52e2345b25 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -254,9 +254,9 @@ Miscellaneous options .. versionchanged:: 3.5 Affects also comparisons of :class:`bytes` with :class:`int`. - .. deprecated-removed:: 3.15 3.17 + .. deprecated:: 3.15 - Deprecate :option:`-b` and :option:`!-bb` + Deprecate :option:`-b` and :option:`!-bb` command line options and schedule them to become no-op in Python 3.17. These were primarily helpers for the Python 2 -> 3 transition. Starting with Python 3.17, no :exc:`BytesWarning` will be raised diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 93fceeec51a428..0bbc7b39c3aec8 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -540,7 +540,7 @@ Deprecated CLI --- -* Deprecate :option:`-b` and :option:`!-bb` +* Deprecate :option:`-b` and :option:`!-bb` command line options and schedule them to become no-op in Python 3.17. These were primarily helpers for the Python 2 -> 3 transition. Starting with Python 3.17, no :exc:`BytesWarning` will be raised @@ -763,6 +763,10 @@ Deprecated C APIs :c:func:`_Py_c_abs` are :term:`soft deprecated`. (Contributed by Sergey B Kirpichev in :gh:`128813`.) +* :c:member:`~PyConfig.bytes_warning` is deprecated + since 3.15 and will be removed in 3.17. + (Contributed by Nikita Sobolev in :gh:`136355`.) + .. Add C API deprecations above alphabetically, not here at the end. diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst index 055126ed1981b0..817291aaa9a688 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst @@ -1,2 +1,5 @@ -Deprecate :option:`-b` and :option:`!-bb` and schedule them -to become no-op in Python 3.17. +Deprecate :option:`-b` and :option:`!-bb` command line options +and schedule them to become no-op in Python 3.17. + +Deprecate :c:member:`PyConfig.bytes_warning` field +and schedule its removal in 3.17. From 7a274305cc573761b6c71bb5a2a7934544bd80c1 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 14 Sep 2025 14:44:37 +0300 Subject: [PATCH 4/6] Update Doc/c-api/init_config.rst Co-authored-by: Victor Stinner --- Doc/c-api/init_config.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 9d9199f708af90..152d1e0b57d91e 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1280,8 +1280,8 @@ PyConfig .. deprecated-removed:: 3.15 3.17 - Deprecated, :option:`-b` and :option:`!-bb` will become no-op in 3.17. - :c:member:`~PyConfig.bytes_warning` will be removed in 3.17. + Deprecated, :option:`-b` and :option:`!-bb` options will become no-op in 3.17. + :c:member:`~PyConfig.bytes_warning` member will be removed in 3.17. .. c:member:: int warn_default_encoding From 3eb29741932689c14efb3f3885bd21b8763f646f Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 14 Sep 2025 14:44:44 +0300 Subject: [PATCH 5/6] Adress review --- .../next/C_API/2025-09-14-14-44-24.gh-issue-136355.LCaYyC.rst | 2 ++ .../2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-09-14-14-44-24.gh-issue-136355.LCaYyC.rst diff --git a/Misc/NEWS.d/next/C_API/2025-09-14-14-44-24.gh-issue-136355.LCaYyC.rst b/Misc/NEWS.d/next/C_API/2025-09-14-14-44-24.gh-issue-136355.LCaYyC.rst new file mode 100644 index 00000000000000..44537729b3f0a3 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-09-14-14-44-24.gh-issue-136355.LCaYyC.rst @@ -0,0 +1,2 @@ +Deprecate :c:member:`PyConfig.bytes_warning` field and schedule its removal +in 3.17. diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst index 817291aaa9a688..dd6bd28c3ff02b 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-07-12-24-00.gh-issue-136355.MTcA8j.rst @@ -1,5 +1,2 @@ Deprecate :option:`-b` and :option:`!-bb` command line options and schedule them to become no-op in Python 3.17. - -Deprecate :c:member:`PyConfig.bytes_warning` field -and schedule its removal in 3.17. From 117872fc5469467bfce94cf3b780f281121aef10 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 14 Sep 2025 14:56:39 +0300 Subject: [PATCH 6/6] Update Doc/c-api/init_config.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/init_config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 152d1e0b57d91e..b20495e672dd75 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1280,7 +1280,7 @@ PyConfig .. deprecated-removed:: 3.15 3.17 - Deprecated, :option:`-b` and :option:`!-bb` options will become no-op in 3.17. + The :option:`-b` and :option:`!-bb` options will become no-op in 3.17. :c:member:`~PyConfig.bytes_warning` member will be removed in 3.17. .. c:member:: int warn_default_encoding