Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r88714:481c5fb368c8 Date: 2016-11-28 18:50 +0100 http://bitbucket.org/pypy/pypy/changeset/481c5fb368c8/
Log: '%b' in unicode strings is not supported diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -503,6 +503,8 @@ raise oefmt(space.w_TypeError, "%c requires int or char") def fmt_b(self, w_value): + if do_unicode: + self.unknown_fmtchar() space = self.space # cpython explicitly checks for bytes & bytearray if space.isinstance_w(w_value, space.w_bytes): @@ -524,7 +526,7 @@ return raise oefmt(space.w_TypeError, - "requires bytes, or an object that" \ + "requires bytes, or an object that " "implements __bytes__, not '%T'", w_value) return StringFormatter diff --git a/pypy/objspace/std/test/test_stringformat.py b/pypy/objspace/std/test/test_stringformat.py --- a/pypy/objspace/std/test/test_stringformat.py +++ b/pypy/objspace/std/test/test_stringformat.py @@ -321,6 +321,10 @@ f = 4 raises(ValueError, '"%\u1234" % (f,)') + def test_invalid_b_with_unicode(self): + raises(ValueError, '"%b" % b"A"') + raises(ValueError, '"%b" % 42') + def test_formatting_huge_precision(self): prec = 2**31 format_string = u"%.{}f".format(prec) @@ -370,6 +374,10 @@ assert b"<%c>" % b"?" == b"<?>" raises(TypeError, 'b"<%c>" % "?"') assert b"<%c>" % bytearray(b"?") == b"<?>" + class X: + def __bytes__(self): + return b'5' + raises(TypeError, 'b"<%c>" % X()') def test_bytes_bytes(self): assert b"<%b>" % b"123" == b"<123>" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit