-
Notifications
You must be signed in to change notification settings - Fork 63
redefinition of unused 'somemodule' from line X #13
Comments
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! |
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:
Substitude _unittest and _WritelnDecorator with the entities (modules, functions, classes) you need |
Any progress on this? if i==1:
def g():
return 1
else:
def g():
return 2 which gives a "redefinition of function" warning. |
Unittests for issue kevinw#13
Do not raise warning on common idioms like try: import something except ImportError: import somethingelse as something Implements a simple check whether duplicate definition or import share a common parent AST node that is either <_ast.If> or <_ast.TryExcept>. In that case additional verification is performed whether duplicate definitions/imports were written together. In case of multiple definitions on different flow control forks (try/except/else, if/else) no warning is raised. No attempt is being made to perform smarter analysis of the case. Should fix most obvious cases of: kevinw#13
Use the work-around fix mentioned in the following pyflakes issue: kevinw/pyflakes#13 This avoids the need to install a patched version of pyflakes until the "#pyflakes:ignore" patch is included in a future release. Once the pyflakes patch is included in a new release this commit should be reverted to using "#pyflakes:ignore" instead.
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.
The text was updated successfully, but these errors were encountered: