Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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]
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
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.

(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\
-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");
}
config->bytes_warning++;
break;

Expand Down
Loading