bpo-28856: Let %b format for bytes support objects that follow the bu… · python/cpython@faa2cc6 (original) (raw)

`@@ -315,10 +315,12 @@ def bytes(self):

`

315

315

`testcommon(b"%b", b"abc", b"abc")

`

316

316

`testcommon(b"%b", bytearray(b"def"), b"def")

`

317

317

`testcommon(b"%b", fb, b"123")

`

``

318

`+

testcommon(b"%b", memoryview(b"abc"), b"abc")

`

318

319

`# # %s is an alias for %b -- should only be used for Py2/3 code

`

319

320

`testcommon(b"%s", b"abc", b"abc")

`

320

321

`testcommon(b"%s", bytearray(b"def"), b"def")

`

321

322

`testcommon(b"%s", fb, b"123")

`

``

323

`+

testcommon(b"%s", memoryview(b"abc"), b"abc")

`

322

324

`# %a will give the equivalent of

`

323

325

`# repr(some_obj).encode('ascii', 'backslashreplace')

`

324

326

`testcommon(b"%a", 3.14, b"3.14")

`

`@@ -377,9 +379,11 @@ def test_exc(formatstr, args, exception, excmsg):

`

377

379

`test_exc(b"%c", 3.14, TypeError,

`

378

380

`"%c requires an integer in range(256) or a single byte")

`

379

381

`test_exc(b"%b", "Xc", TypeError,

`

380

``

`-

"%b requires bytes, or an object that implements bytes, not 'str'")

`

``

382

`+

"%b requires a bytes-like object, "

`

``

383

`+

"or an object that implements bytes, not 'str'")

`

381

384

`test_exc(b"%s", "Wd", TypeError,

`

382

``

`-

"%b requires bytes, or an object that implements bytes, not 'str'")

`

``

385

`+

"%b requires a bytes-like object, "

`

``

386

`+

"or an object that implements bytes, not 'str'")

`

383

387

``

384

388

`if maxsize == 2**31-1:

`

385

389

`# crashes 2.2.1 and earlier:

`