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

Possible simplification for old-style exception handling code in stdlib #60345

Closed
gvanrossum opened this issue Oct 5, 2012 · 5 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

BPO 16141
Nosy @gvanrossum, @vsajip, @ronaldoussoren, @bitdancer, @serhiy-storchaka
Files
  • reraise_keyboard_interrupt.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 = None
    closed_at = <Date 2013-05-01.13:46:54.025>
    created_at = <Date 2012-10-05.14:46:26.408>
    labels = ['type-bug', 'library']
    title = 'Possible simplification for old-style exception handling code in stdlib'
    updated_at = <Date 2013-05-01.13:46:54.011>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2013-05-01.13:46:54.011>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-05-01.13:46:54.025>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2012-10-05.14:46:26.408>
    creator = 'gvanrossum'
    dependencies = []
    files = ['27435']
    hgrepos = []
    issue_num = 16141
    keywords = ['patch']
    message_count = 5.0
    messages = ['172087', '172104', '172452', '188212', '188225']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'vinay.sajip', 'ronaldoussoren', 'r.david.murray', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16141'
    versions = ['Python 3.4']

    @gvanrossum
    Copy link
    Member Author

    I just noticed that StreamHandler contains the following fragment in its emit() method:

    try:
    <do some writing>
    except (KeyboardInterrupt, SystemExit): #pragma: no cover
    raise
    except:
    self.handleError(record)

    Couldn't this be simplified to the following?

    try:
    <do some writing>
    except Exception:
    self.handleError(record)

    I.e. instead of manually catching and re-raising a few BaseExceptions, just don't catch anything that derives from BaseException but not from Exception?

    (I noticed because we have an internal clone of this class that occasionally gets augmented with yet another base exception that shouldn't be handled.

    @gvanrossum gvanrossum added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 5, 2012
    @serhiy-storchaka
    Copy link
    Member

    Couldn't this be simplified to the following?

    I think this is idiomatic now (since 2.5).

    There are some places where similar outdated code used. See the attached patch. There are more dubious places in Lib/multiprocessing/managers.py and Lib/asyncore.py.

    @vsajip vsajip self-assigned this Oct 8, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 9, 2012

    New changeset 46889b772442 by Vinay Sajip in branch 'default':
    Issue bpo-16141: replaced old-style exception handling code in logging with the modern idiom.
    http://hg.python.org/cpython/rev/46889b772442

    @vsajip vsajip changed the title Possible simplification for logging.StreamHandler exception handling Possible simplification for old-style exception handling code in stdlib Oct 9, 2012
    @vsajip vsajip removed their assignment Oct 9, 2012
    @ronaldoussoren
    Copy link
    Contributor

    Shouldn't this issue be closed? (the proposed patch was applied in Oct. last year)

    @bitdancer
    Copy link
    Member

    I'm guessing Serhiy left it open because of the question about multiprocessing and asyncore. Given that he rated them as dubious, let's just close it.

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

    No branches or pull requests

    5 participants