Created on 2014-01-21 21:45 by rndblnch, last changed 2022-04-11 14:57 by admin. This issue is now closed.
% python3
Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help(bytes)
bytes constructor accepts more than one argument even of the first one is not a string (and then the other arguments are checked to be strings):
>>> bytes(2, "foo", "bar")
b'\x00\x00'
>>> bytes(2, "foo")
b'\x00\x00'
but:
>>> bytes(2, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: bytes() argument 2 must be str, not int
This shows the report to be wrong, you either have to pass an iterable of ints or a single int. Even the title is wrong, it doesn't accept more than one argument if the first one isn't a string, it raises a TypeError. Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help(bytes) Help on class bytes in module builtins: class bytes(object) | bytes(iterable_of_ints) -> bytes | bytes(string, encoding[, errors]) -> bytes | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer | bytes(int) -> bytes object of size given by the parameter initialized with null bytes | bytes() -> empty bytes object
LGTM. Do you want to provide a test Renaud?
Here is a patch with tests.
New changeset 8badbd65840e by Serhiy Storchaka in branch '3.4': Issue #20335: bytes constructor now raises TypeError when encoding or errors https://hg.python.org/cpython/rev/8badbd65840e New changeset 8d6b27837c69 by Serhiy Storchaka in branch 'default': Issue #20335: bytes constructor now raises TypeError when encoding or errors https://hg.python.org/cpython/rev/8d6b27837c69
Thank you for your patch Renaud.
resolution: fixed
stage: patch review -> resolved
messages:
+ msg231952
stage: test needed -> patch review
messages:
+ msg227675
stage: test needed