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

random.choice on empty sequence should hide previous exception [patch] #73241

Closed
then0rTh mannequin opened this issue Dec 23, 2016 · 4 comments
Closed

random.choice on empty sequence should hide previous exception [patch] #73241

then0rTh mannequin opened this issue Dec 23, 2016 · 4 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@then0rTh
Copy link
Mannequin

then0rTh mannequin commented Dec 23, 2016

BPO 29055
Nosy @rhettinger, @mdickinson, @MojoVampire
Files
  • random_choice_errmsg.patch: patch for random.py
  • 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/rhettinger'
    closed_at = <Date 2016-12-27.09:09:33.828>
    created_at = <Date 2016-12-23.15:56:57.938>
    labels = ['3.7', 'type-bug', 'library']
    title = 'random.choice on empty sequence should hide previous exception [patch]'
    updated_at = <Date 2016-12-27.09:09:33.786>
    user = 'https://bugs.python.org/then0rTh'

    bugs.python.org fields:

    activity = <Date 2016-12-27.09:09:33.786>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2016-12-27.09:09:33.828>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2016-12-23.15:56:57.938>
    creator = 'then0rTh'
    dependencies = []
    files = ['46007']
    hgrepos = []
    issue_num = 29055
    keywords = ['patch']
    message_count = 4.0
    messages = ['283884', '283886', '284074', '284075']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'python-dev', 'josh.r', 'then0rTh']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29055'
    versions = ['Python 3.6', 'Python 3.7']

    @then0rTh
    Copy link
    Mannequin Author

    then0rTh mannequin commented Dec 23, 2016

    Passing empty sequence to random.choice function leads to:

    Traceback (most recent call last):
      ...
    ValueError: number of bits must be greater than zero
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      ...
    IndexError: Cannot choose from an empty sequence
    • the ValueError doesn't add any useful information, only bloats stderr
    • the "During handling" line indicates that something went wrong inside random.py

    This patch uses raise x from None to hide the ValueError, resulting in much cleaner output.

    -Tested on Python 3.7.0a0

    @then0rTh then0rTh mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 23, 2016
    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Dec 23, 2016

    Seems reasonable to me.

    @rhettinger rhettinger self-assigned this Dec 27, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 27, 2016

    New changeset 0001ae913759 by Raymond Hettinger in branch '3.6':
    Issue bpo-29055: Suppress upstream exception for random.choice()
    https://hg.python.org/cpython/rev/0001ae913759

    @rhettinger
    Copy link
    Contributor

    Thanks for the patch.

    Please submit a contributor agreement for future work. We would like to have it for all patches (though this one was so tiny it isn't strictly required).

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant