Detect misuse of except

Bug #848455 reported by Tristan Seligmann
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Pyflakes
New
Wishlist
Unassigned
pyflakes (Debian)
Confirmed
Unknown

Bug Description

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

       try:
           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
Revision history for this message
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
Revision history for this message
Wilfred Hughes (yatc18ks0-9a-ngeefk4xa) wrote :

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

Revision history for this message
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.

Revision history for this message
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
Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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