classification
Title: bytes constructor accepts more than one argument even if the first one is not a string
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, rndblnch, serhiy.storchaka
Priority: low Keywords: patch

Created on 2014-01-21 21:45 by rndblnch, last changed 2014-12-02 07:39 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
bytesobject.patch rndblnch, 2014-01-21 22:13 patch that puts the existing check at the right place review
issue20335.patch serhiy.storchaka, 2014-12-01 17:57 review
Messages (6)
msg208707 - (view) Author: Renaud Blanch (rndblnch) Date: 2014-01-21 21:45
% 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
msg208710 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-01-21 22:04
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
msg227675 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-27 14:18
LGTM. Do you want to provide a test Renaud?
msg231952 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-01 17:57
Here is a patch with tests.
msg231976 - (view) Author: Roundup Robot (python-dev) Date: 2014-12-02 07:35
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
msg231977 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-02 07:39
Thank you for your patch Renaud.
History
Date User Action Args
2014-12-02 07:39:08serhiy.storchakasetstatus: open -> closed
versions: - Python 2.7
messages: + msg231977

resolution: fixed
stage: patch review -> resolved
2014-12-02 07:35:19python-devsetnosy: + python-dev
messages: + msg231976
2014-12-01 17:57:26serhiy.storchakasetfiles: + issue20335.patch

messages: + msg231952
stage: test needed -> patch review
2014-10-12 16:25:49serhiy.storchakasetpriority: normal -> low
2014-09-27 14:18:29serhiy.storchakasetassignee: serhiy.storchaka
type: behavior
versions: + Python 2.7, Python 3.4, Python 3.5, - Python 3.3
nosy: + serhiy.storchaka

messages: + msg227675
stage: test needed
2014-02-03 15:36:34BreamoreBoysetnosy: - BreamoreBoy
2014-01-21 22:15:28rndblnchsettitle: bytes constructor accepts more than one argument even of the first one is not a string -> bytes constructor accepts more than one argument even if the first one is not a string
2014-01-21 22:13:04rndblnchsetfiles: + bytesobject.patch
keywords: + patch
2014-01-21 22:04:02BreamoreBoysetnosy: + BreamoreBoy
messages: + msg208710
2014-01-21 21:45:37rndblnchcreate