Detect misuse of except

Bug #848455 reported by Tristan Seligmann on 2011-09-13
This bug affects 3 people
Affects Status Importance Assigned to Milestone
pyflakes (Debian)

Bug Description

It would be nice if pyflakes could detect mistakes like this:

           oldtime = os.path.getmtime(fname)
       except OSError, IOError:
           oldtime = 0

In the general case, it's obviously difficult to tell whether this is an error or not; but I suspect that handling the exception variable name as a binding would give you a "redefinition of Foo" warning in most of the cases where a mistake has been made.

Changed in pyflakes:
importance: Undecided → Wishlist
Jean-Paul Calderone (exarkun) wrote :

Sounds reasonable. At least it would be interesting to run such a check against existing codebases to see what comes up. :)

Changed in pyflakes (Debian):
status: Unknown → New
Changed in pyflakes (Debian):
status: New → Confirmed

Pyflakes 0.5.0 does generate the warning "local variable 'IOError' is assigned to but never used", so I believe this has been fixed.

Tristan Seligmann (mithrandi) wrote :

You only get the unused-local-variable warning if the try/except is in a function. However, it looks like pyflakes does not warn about shadowing builtins, which I thought it did, so my analysis in the description is probably wrong.

Marcin Cieślak (saperski) wrote :

There is no warning as of pyflakes 0.7.3, marking as fixed

Changed in pyflakes:
status: New → Fix Released
Marcin Cieślak (saperski) wrote :

er, sorry, misunderstood... should be reopened again

Changed in pyflakes:
status: Fix Released → New
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.