[issue21259] replace "except: pass" by "except Exception: pass"

Raymond Hettinger report at bugs.python.org
Wed Apr 16 21:53:00 CEST 2014


Raymond Hettinger added the comment:

FYI, the two are not equivalent.   A bare except is equivalent to BaseException.  Even then, the new code would be slower than the original, so I'm not sure this change should be made at all (it makes the code more verbose, slower, and risks introducing a semantic change).

Also, Guido traditionally tries to discourage across the board changes like this.  Instead, we aim for "holistic refactoring" where code improvements are being made one module at a time by someone who deeply groks the code and is thinking through all the changes.  The problem with across-the-board edits is that they tend to be very shallow "change thing x to thing y" without looking at what the surrounding code is doing or whether the code ever made sense in the first place.

Another part of the risk of semantic change is that we likely do not have specific tests for Exception vs BaseException so it would be easy to make a mistake and not have the test suite catch it.

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21259>
_______________________________________


More information about the Python-bugs-list mailing list