Author: Sebastian Pawlu? <[email protected]>
Branch: py3.3
Changeset: r76037:3f49d90dbd9e
Date: 2015-02-21 18:45 +0100
http://bitbucket.org/pypy/pypy/changeset/3f49d90dbd9e/
Log: (xando, mjacob) Don't allow integer like objects with bytes
constructor, although regular integers should be allowed
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -685,7 +685,7 @@
return []
# Is it an int?
try:
- count = space.int_w(w_source)
+ count = space.int_w(w_source, allow_conversion=False)
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
diff --git a/pypy/objspace/std/test/test_bytesobject.py
b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -823,6 +823,13 @@
assert bytes.maketrans(bb, bb)
assert bytearray.maketrans(bb, bb)
+ def test_constructor_dont_convert_int(self):
+ class A(object):
+ def __int__(self):
+ return 42
+ raises(TypeError, bytes, A())
+
+
class AppTestPrebuilt(AppTestBytesObject):
spaceconfig = {"objspace.std.withprebuiltchar": True}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit