pyflakes
pyflakes copied to clipboard
redefinition of unused 'somemodule' from line X
try:
import simplejson as json
except ImportError:
import json
with open('file.json') as fh:
json.load(fh)
The previous block of code will generate the error "redefinition of unused 'json' from line 4 ". But in this case I don't see why it should be an error.
Although different in context, it might be related to this issue.
This annoys me too, but I'm not 100% sure how to generalize it into something that doesn't miss actual errors.
But yeah: imports that are inside a try/except ImportError: block could be marked as such, and then if redefined in the except block, not raise a message. I'll give it a shot for the next release!
Although different in context, it might be related to this issue.
That issue is separate and has been resolved. The case reported here still occurs in the latest version.
I'll be waiting for the fix. Thanks for the quick reply.
While the fix is still coming, this is how it can be worked around, if you're wondering:
try:
from unittest.runner import _WritelnDecorator
_WritelnDecorator; # workaround for pyflakes issue #13
except ImportError:
from unittest import _WritelnDecorator
Substitude _unittest and _WritelnDecorator with the entities (modules, functions, classes) you need
Any progress on this? A related issue is code like this:
if i==1:
def g():
return 1
else:
def g():
return 2
which gives a "redefinition of function" warning.