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 and bytearray constructors replace unexpected exceptions #79155

Closed
serhiy-storchaka opened this issue Oct 13, 2018 · 5 comments
Closed
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 34974
Nosy @abalkin, @methane, @serhiy-storchaka, @miss-islington
PRs
  • bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). #9852
  • [3.7] bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852) #9878
  • [3.6] bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852) #9879
  • [2.7] bpo-34974: Do not replace unexpected errors in bytearray(). (GH-9852) #9885
  • 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 2018-10-15.05:46:54.510>
    created_at = <Date 2018-10-13.19:18:56.703>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = 'bytes and bytearray constructors replace unexpected exceptions'
    updated_at = <Date 2018-10-15.05:46:54.510>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-10-15.05:46:54.510>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2018-10-15.05:46:54.510>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2018-10-13.19:18:56.703>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34974
    keywords = ['patch']
    message_count = 5.0
    messages = ['327661', '327721', '327722', '327723', '327730']
    nosy_count = 4.0
    nosy_names = ['belopolsky', 'methane', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['9852', '9878', '9879', '9885']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34974'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @serhiy-storchaka
    Copy link
    Member Author

    bytes() and bytearray() replace some unexpected exceptions (including MemoryError and KeyboardInterrupt) with TypeError.

    1. Exception in __index__.
    class X:
        def __index__(self):
            raise MemoryError

    bytes(X()) results in:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: cannot convert 'X' object to bytes

    bytearray(X()) results in:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'X' object is not iterable

    This is related to bpo-29159.

    1. Exception in __iter__.
    class X:
        def __iter__(self):
            raise MemoryError

    bytes(X()) results in:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: cannot convert 'X' object to bytes

    bytearray(X()) works correctly (raises a MemoryError).

    The proper solution is to replace just a TypeError and allow other exceptions to emerge.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes labels Oct 13, 2018
    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 13, 2018
    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 13, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset e890421 by Serhiy Storchaka in branch 'master':
    bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)
    e890421

    @miss-islington
    Copy link
    Contributor

    New changeset 1370832 by Miss Islington (bot) in branch '3.7':
    bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)
    1370832

    @miss-islington
    Copy link
    Contributor

    New changeset 08ba7eb by Miss Islington (bot) in branch '3.6':
    bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)
    08ba7eb

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 43308df by Serhiy Storchaka in branch '2.7':
    [2.7] bpo-34974: Do not replace unexpected errors in bytearray(). (GH-9852) (GH-9885)
    43308df

    @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
    3.7 (EOL) end of life 3.8 only security fixes 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

    2 participants