Skip to content
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

bytes constructor accepts more than one argument even if the first one is not a string #64534

Closed
rndblnch mannequin opened this issue Jan 21, 2014 · 6 comments
Closed
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@rndblnch
Copy link
Mannequin

rndblnch mannequin commented Jan 21, 2014

BPO 20335
Nosy @serhiy-storchaka
Files
  • bytesobject.patch: patch that puts the existing check at the right place
  • issue20335.patch
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-12-02.07:39:08.991>
    created_at = <Date 2014-01-21.21:45:37.929>
    labels = ['interpreter-core', 'type-bug']
    title = 'bytes constructor accepts more than one argument even if the first one is not a string'
    updated_at = <Date 2014-12-02.07:39:08.989>
    user = 'https://bugs.python.org/rndblnch'

    bugs.python.org fields:

    activity = <Date 2014-12-02.07:39:08.989>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-12-02.07:39:08.991>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2014-01-21.21:45:37.929>
    creator = 'rndblnch'
    dependencies = []
    files = ['33600', '37337']
    hgrepos = []
    issue_num = 20335
    keywords = ['patch']
    message_count = 6.0
    messages = ['208707', '208710', '227675', '231952', '231976', '231977']
    nosy_count = 3.0
    nosy_names = ['rndblnch', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20335'
    versions = ['Python 3.4', 'Python 3.5']

    @rndblnch
    Copy link
    Mannequin Author

    rndblnch mannequin commented Jan 21, 2014

    % 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

    @rndblnch rndblnch mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 21, 2014
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jan 21, 2014

    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

    @rndblnch rndblnch mannequin changed the title 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 Jan 21, 2014
    @serhiy-storchaka
    Copy link
    Member

    LGTM. Do you want to provide a test Renaud?

    @serhiy-storchaka serhiy-storchaka self-assigned this Sep 27, 2014
    @serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label Sep 27, 2014
    @serhiy-storchaka
    Copy link
    Member

    Here is a patch with tests.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 2, 2014

    New changeset 8badbd65840e by Serhiy Storchaka in branch '3.4':
    Issue bpo-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 bpo-20335: bytes constructor now raises TypeError when encoding or errors
    https://hg.python.org/cpython/rev/8d6b27837c69

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your patch Renaud.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant