Make pyflakes/pylint ignore unused imports

Posted by in Software

Sometimes, you need to add an import without explicitly using it, just to have stuff defined. In such cases, both pyflakes and pylint generate messages, which can be annoying.

For example django-appconf has a class-based configuration like so:

If I’m using the file like this, then I’ll end up with both pylint and pyflakes complaining that settings is unused, although it actually is (when the file gets imported and parsed). You can silence pylint by placing a comment on the import line (or in a pylintrc file to have it as a global option):

but there’s nothing you can do to pyflakes. So, the solution found is somewhat hacky:

It’s just using assert as a “usage” of the empty import.


A little experiment: If you find this post and ad below useful, please check the ad out :-)