Skip to content

Commit 499343c

Browse files
committed
gh-136355: Deprecate -b and -bb CLI flags in 3.15
1 parent 85b817d commit 499343c

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

Doc/using/cmdline.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ Miscellaneous options
254254
.. versionchanged:: 3.5
255255
Affects also comparisons of :class:`bytes` with :class:`int`.
256256

257+
.. deprecated-removed:: 3.15 3.17
258+
259+
Deprecate :option:`-b` and :option:`-bb`
260+
and schedule them for removal in Python 3.17.
261+
They were mainly a transition helpers for Python2 -> Python3 era.
262+
In 3.17 no :exc:`BytesWarning` won't be raised for these cases.
263+
If you want to check for the same things in the future,
264+
use any type-checker of your choice.
265+
266+
257267
.. option:: -B
258268

259269
If given, Python won't try to write ``.pyc`` files on the

Doc/whatsnew/3.15.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ module_name
206206
Deprecated
207207
==========
208208

209+
CLI
210+
---
211+
212+
* Deprecate :option:`-b` and :option:`!-bb`
213+
and schedule them for removal in Python 3.17.
214+
They were mainly a transition helpers for Python2 -> Python3 era.
215+
In 3.17 no :exc:`BytesWarning` won't be raised for these cases.
216+
If you want to check for the same things in the future,
217+
use any type-checker of your choice.
218+
219+
(Contributed by Nikita Sobolev in :gh:`136355`.)
220+
209221
hashlib
210222
-------
211223

Lib/test/test_cmd_line.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def _kill_python_and_exit_code(p):
3232
return data, returncode
3333

3434

35+
b_deprecation_msg = (
36+
'-b option is deprecated since Python 3.15 '
37+
'and will be removed in Python 3.17'
38+
)
39+
40+
3541
class CmdLineTest(unittest.TestCase):
3642
def test_directories(self):
3743
assert_python_failure('.')
@@ -706,7 +712,7 @@ def run_xdev(self, *args, check_exitcode=True, xdev=True):
706712
env=env)
707713
if check_exitcode:
708714
self.assertEqual(proc.returncode, 0, proc)
709-
return proc.stdout.rstrip()
715+
return self.maybe_remove_b_deprecation_msg(proc.stdout)
710716

711717
@support.cpython_only
712718
def test_xdev(self):
@@ -789,7 +795,22 @@ def check_warnings_filters(self, cmdline_option, envvar, use_pywarning=False):
789795
universal_newlines=True,
790796
env=env)
791797
self.assertEqual(proc.returncode, 0, proc)
792-
return proc.stdout.rstrip()
798+
return self.maybe_remove_b_deprecation_msg(proc.stdout)
799+
800+
def maybe_remove_b_deprecation_msg(self, output):
801+
return output.replace(b_deprecation_msg + '\n', '').rstrip()
802+
803+
def test_b_deprecation_msg_stderr(self):
804+
for arg in ['-b', '-bb']:
805+
with self.subTest(arg=arg):
806+
args = (sys.executable, arg, '-c', '')
807+
proc = subprocess.run(args,
808+
stdout=subprocess.PIPE,
809+
stderr=subprocess.PIPE,
810+
universal_newlines=True)
811+
self.assertEqual(proc.returncode, 0, proc)
812+
self.assertEqual(proc.stdout, '')
813+
self.assertEqual(proc.stderr.rstrip(), b_deprecation_msg)
793814

794815
def test_warnings_filter_precedence(self):
795816
expected_filters = ("error::BytesWarning "
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate :option:`-b` and :option:`!-bb` and schedule them
2+
for removal in the future versions of Python.

Python/initconfig.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ static const char usage_help[] = "\
256256
Options (and corresponding environment variables):\n\
257257
-b : issue warnings about converting bytes/bytearray to str and comparing\n\
258258
bytes/bytearray with str or bytes with int. (-bb: issue errors)\n\
259+
deprecated since 3.15 and will be removed in 3.17\n\
259260
-B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x\n\
260261
-c cmd : program passed in as string (terminates option list)\n\
261262
-d : turn on parser debugging output (for experts only, only works on\n\
@@ -2944,6 +2945,11 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,
29442945
return _PyStatus_EXIT(0);
29452946

29462947
case 'b':
2948+
if (!config->bytes_warning) {
2949+
fprintf(stderr,
2950+
"-b option is deprecated since Python 3.15 "
2951+
"and will be removed in Python 3.17\n");
2952+
}
29472953
config->bytes_warning++;
29482954
break;
29492955

0 commit comments

Comments
 (0)