Skip to content

gh-136355: Deprecate -b and -bb CLI flags in 3.15 #136363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@
.. versionchanged:: 3.5
Affects also comparisons of :class:`bytes` with :class:`int`.

.. deprecated-removed:: 3.15 3.17

Deprecate :option:`-b` and :option:`-bb`

Check warning on line 259 in Doc/using/cmdline.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

unknown option: '-bb' [ref.option]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Deprecate :option:`-b` and :option:`-bb`
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.
Comment on lines +261 to +264
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on MAL and Stan's good suggestions:

Suggested change
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.
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.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested improved wording:

      and schedule them for removal in Python 3.17.
      They were mainly meant as transition helpers for Python2 -> Python3 era.
      Starting with 3.17, the :exc:`BytesWarning` will be dropped for these cases.
      If you want to check for the same things in the future,
      please use a type-checker of your choice.

Copy link
Member

@StanFromIreland StanFromIreland Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest slightly simpler;

      and schedule them for removal in Python 3.17.
      These were primarily helpers for the Python2 -> Python3 transition.
      Starting with 3.17, no :exc:`BytesWarning` will be raised for these cases.
      If you want to check for the same things in the future, use a type-checker.


.. option:: -B

If given, Python won't try to write ``.pyc`` files on the
Expand Down
12 changes: 12 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +214 to +217
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion as above.

Copy link
Member

@StanFromIreland StanFromIreland Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must have forgotten to add the other suggestion, only one (this) appears for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, Github's UI is a nightmare. Added it again.

(Contributed by Nikita Sobolev in :gh:`136355`.)

hashlib
-------

Expand Down
25 changes: 23 additions & 2 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate :option:`-b` and :option:`!-bb` and schedule them
for removal in the future versions of Python.
6 changes: 6 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
deprecated since 3.15 and will be removed in 3.17\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\
Expand Down Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to move this code at the end of pyinit_core() (before done: label). Example:

    if (_Py_GetConfig()->bytes_warning) {
        fprintf(stderr,
                "-b option is deprecated since Python 3.15 "
                "and will be removed in Python 3.17\n");
    }

So it deprecates indirectly the PyConfig.bytes_warning member.

}
config->bytes_warning++;
break;

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy