homepage

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: Fix bare excepts in various places in std lib
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Ramchandra Apte, asvetlov, brett.cannon, eric.araujo, ezio.melotti, martin.panter, python-dev, sbt, serhiy.storchaka, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2012年10月17日 08:06 by Ramchandra Apte, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch.patch Ramchandra Apte, 2013年01月09日 13:51
bare_except.patch serhiy.storchaka, 2013年01月09日 14:33 Regenerated for Rietveld review
Messages (20)
msg173140 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012年10月17日 08:06
Will attach patch.
msg173175 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012年10月17日 13:50
One thing to be aware of, Ramchandra, is that there might be a slight backwards-compatibility problem from tightening up what exceptions propagate. Now with proper documentation and only applying things to 3.4 this probably won't be a problem.
msg174264 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012年10月31日 05:04
This seems quite difficult for one person;there are 589 lines having "except:"
I'll work on the Tools directory.
If anybody wants to help, please tell which folder you will do.
msg174403 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012年11月01日 11:51
I'm pretty sure Doc and Lib are already fixed, only Tools left.
msg174406 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012年11月01日 12:26
On 1 November 2012 17:21, Andrew Svetlov <report@bugs.python.org> wrote:
>
> Andrew Svetlov added the comment:
>
> I'm pretty sure Doc and Lib are already fixed, only Tools left.
>
> ----------
> nosy: +asvetlov
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16261>
> _______________________________________
>
No. 405 are there in Lib. Try running `grep "except:" -R Lib --include
"*.py"` to see yourself.
msg174452 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012年11月01日 19:36
Sorry, looks like I don't understood you correctly.
Do you want to replace `except:` to `except Exception` or something else?
msg174489 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012年11月02日 04:42
Yes.
most of the bare excepts can be replaced with a stricter clause
On 2 November 2012 01:06, Andrew Svetlov <report@bugs.python.org> wrote:
>
> Andrew Svetlov added the comment:
>
> Sorry, looks like I don't understood you correctly.
> Do you want to replace `except:` to `except Exception` or something else?
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16261>
> _______________________________________
>
msg174564 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年11月02日 20:07
New changeset b2bd62d1644f by Andrew Svetlov in branch 'default':
Issue #16261: fix bare excepts in Doc/
http://hg.python.org/cpython/rev/b2bd62d1644f 
msg174565 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012年11月02日 20:10
I've fixed bare except: in docs.
Tomorrow we will have Python sprint in Kiev.
Maybe somebody will take a look on Lib.
msg179441 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013年01月09日 13:47
Here's a patch on revision 75fe7f5fda9a (I did it on a trip without an internet connection)
There might be some mistakes of this type:
I incorrectly changed instances like this
`
try:
 something
except:
 close file
 raise
`
to
`
try:
 something
finally:
 close file
`
(the incorrect version closes the file always)
msg179442 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013年01月09日 13:51
Sorry, I entered the wrong filename for the patch and so it didn't get attached. Now I have attached it.
msg179445 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013年01月09日 14:33
Unhappy Rietveld hasn't recognize your patch. I have regenerated it.
msg179448 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013年01月09日 15:00
> try:
> _MAXFD = os.sysconf("SC_OPEN_MAX")
> -except:
> +except ValueError:
> _MAXFD = 256
os.sysconf() might raise OSError. I think ValueError is only raised if _SC_OPEN_MAX was undefined when the module was compiled.
msg179449 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013年01月09日 15:05
See my comments on Rietveld.
msg179456 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013年01月09日 15:45
Want to make a few warnings. Accepting your confirmation may take a long time. And it is very unlikely that your patch can be applied as a whole. The maintainers of the individual modules can apply it by parts.
msg202448 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013年11月08日 22:39
The earlier #15313 is about removing bare excepts in Idle code. These should be handled separately for two reasons.
1. Changes can and in most cases should be backported.
2. As with any other Python-coded application, uncaught exceptions cause Idle to quit. Currently, if Idle is started directly, rather than from a console, such an exit looks like a silent crash. So either the added tuple of exceptions to be caught must be complete, or the calling code must be adjusted.
I copied the one idlelib fix (to PyShell.py) to that issue for separate examination. It should be removed from any patch applied here.
msg216810 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014年04月18日 22:01
See more discussion on duplicate #21259.
msg243639 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015年05月20日 02:16
I reviewed the patch on Reitveld. All of the changes that do not have comments look okay to me, although some will definitely have merge conflicts with the current code. If someone updated the patch based on the comments, I think it may be okay to commit.
msg243650 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年05月20日 07:34
New changeset b3a7215b9ce4 by Serhiy Storchaka in branch 'default':
Issue #16261: Converted some bare except statements to except statements
https://hg.python.org/cpython/rev/b3a7215b9ce4 
msg243651 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015年05月20日 07:35
Resolved conflicts, fixed some noted issues in the patch and committed unquestionable changes. Thank you for your patch Ramchandra.
History
Date User Action Args
2022年04月11日 14:57:37adminsetgithub: 60465
2015年09月19日 06:02:44martin.panterlinkissue21259 superseder
2015年05月20日 07:35:47serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg243651

stage: patch review -> resolved
2015年05月20日 07:34:07python-devsetmessages: + msg243650
2015年05月20日 07:21:54serhiy.storchakasetassignee: serhiy.storchaka
stage: needs patch -> patch review
versions: + Python 3.5, - Python 3.4
2015年05月20日 02:16:33martin.pantersetnosy: + martin.panter

messages: + msg243639
stage: needs patch
2014年04月18日 22:01:41terry.reedysetmessages: + msg216810
2013年11月08日 22:39:39terry.reedysetnosy: + terry.reedy
messages: + msg202448
2013年11月08日 19:32:29ezio.melottisetnosy: + ezio.melotti
2013年11月07日 21:57:23vstinnersetnosy: + vstinner
2013年01月09日 15:45:36serhiy.storchakasetmessages: + msg179456
2013年01月09日 15:05:43serhiy.storchakasetmessages: + msg179449
2013年01月09日 15:00:18sbtsetnosy: + sbt
messages: + msg179448
2013年01月09日 14:33:58serhiy.storchakasetfiles: + bare_except.patch
nosy: + serhiy.storchaka
messages: + msg179445

2013年01月09日 13:51:07Ramchandra Aptesetfiles: + patch.patch
keywords: + patch
messages: + msg179442
2013年01月09日 13:47:15Ramchandra Aptesetmessages: + msg179441
2012年11月02日 20:10:18asvetlovsetmessages: + msg174565
2012年11月02日 20:07:37python-devsetnosy: + python-dev
messages: + msg174564
2012年11月02日 04:42:27Ramchandra Aptesetmessages: + msg174489
2012年11月01日 19:36:39asvetlovsetmessages: + msg174452
2012年11月01日 12:26:01Ramchandra Aptesetmessages: + msg174406
2012年11月01日 11:51:57asvetlovsetnosy: + asvetlov
messages: + msg174403
2012年10月31日 05:04:15Ramchandra Aptesetmessages: + msg174264
2012年10月30日 13:40:51Ramchandra Aptesettype: behavior
2012年10月19日 16:17:56eric.araujosetnosy: + eric.araujo

versions: + Python 3.4
2012年10月17日 13:50:08brett.cannonsetnosy: + brett.cannon
messages: + msg173175
2012年10月17日 08:06:05Ramchandra Aptecreate

AltStyle によって変換されたページ (->オリジナル) /