This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Possible simplification for old-style exception handling code in stdlib
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, python-dev, r.david.murray, ronaldoussoren, serhiy.storchaka, vinay.sajip
Priority: normal Keywords: patch

Created on 2012-10-05 14:46 by gvanrossum, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
reraise_keyboard_interrupt.patch serhiy.storchaka, 2012-10-05 17:41 review
Messages (5)
msg172087 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2012-10-05 14:46
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.
msg172104 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-05 17:41
> 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.
msg172452 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-09 07:06
New changeset 46889b772442 by Vinay Sajip in branch 'default':
Issue #16141: replaced old-style exception handling code in logging with the modern idiom.
http://hg.python.org/cpython/rev/46889b772442
msg188212 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-01 11:58
Shouldn't this issue be closed? (the proposed patch was applied in Oct. last year)
msg188225 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-05-01 13:46
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.
History
Date User Action Args
2022-04-11 14:57:36adminsetgithub: 60345
2013-05-01 13:46:54r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg188225

resolution: fixed
stage: patch review -> resolved
2013-05-01 11:58:31ronaldoussorensetnosy: + ronaldoussoren
messages: + msg188212
2012-10-09 07:08:59vinay.sajipsetassignee: vinay.sajip ->
title: Possible simplification for logging.StreamHandler exception handling -> Possible simplification for old-style exception handling code in stdlib
2012-10-09 07:06:25python-devsetnosy: + python-dev
messages: + msg172452
2012-10-08 23:13:19vinay.sajipsetassignee: vinay.sajip
2012-10-05 18:13:30pitrousetnosy: + vinay.sajip

stage: patch review
2012-10-05 17:41:40serhiy.storchakasetfiles: + reraise_keyboard_interrupt.patch

nosy: + serhiy.storchaka
messages: + msg172104

keywords: + patch
2012-10-05 14:46:26gvanrossumcreate