Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r87849:114c84700787 Date: 2016-10-17 21:32 +0200 http://bitbucket.org/pypy/pypy/changeset/114c84700787/
Log: Disallow int(memoryview(), base) diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py --- a/pypy/objspace/std/intobject.py +++ b/pypy/objspace/std/intobject.py @@ -902,13 +902,12 @@ if space.isinstance_w(w_value, space.w_unicode): from pypy.objspace.std.unicodeobject import unicode_to_decimal_w s = unicode_to_decimal_w(space, w_value, allow_surrogates=True) + elif (space.isinstance_w(w_value, space.w_bytes) or + space.isinstance_w(w_value, space.w_bytearray)): + s = space.bufferstr_w(w_value) else: - try: - s = space.bufferstr_w(w_value) - except OperationError as e: - raise oefmt(space.w_TypeError, - "int() can't convert non-string with explicit " - "base") + raise oefmt(space.w_TypeError, + "int() can't convert non-string with explicit base") return _string_to_int_or_long(space, w_inttype, w_value, s, base) diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py --- a/pypy/objspace/std/test/test_intobject.py +++ b/pypy/objspace/std/test/test_intobject.py @@ -602,6 +602,11 @@ assert m is False assert len(log) == 2 + def test_int_nonstr_with_base(self): + assert int(b'100', 2) == 4 + assert int(bytearray(b'100'), 2) == 4 + raises(TypeError, int, memoryview(b'100'), 2) + class AppTestIntShortcut(AppTestInt): spaceconfig = {"objspace.std.intshortcut": True} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit