-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bytes constructor accepts more than one argument even if the first one is not a string #64534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
% 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': New changeset 8d6b27837c69 by Serhiy Storchaka in branch 'default': |
Thank you for your patch Renaud. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: