Search code examples
pythonpython-importpep8flake8

Make flake8 differentiate between undefined functions and star imports


I have a rather large project that I'm trying to clean up before posting, but when I run flake8 I get tons of

'F405 <function> may be undefined, or defined from star imports: generic_functions`

I could avoid this by replacing the line:

from generic_functions import *

at the start of my file, but:

  1. I literally use all of the functions in there, so I don't understand how it's more pythonic to exceed the 80 character limit typing out every single function:

     from generic_functions import (function1, function2, function3, function4, function5, function6, function7...)
    
  2. Doing the above would be tedious, especially if I need to add or remove from the dozens of functions in generic_functions.py

The other option would be to disable the F405 warning, but what if the function is truly undefined? It would be nice to allow star imports while still catching anything undefined. Is there a way to do this? I tried adding # noqa to the import line, but it doesn't seem to help.


Solution

  • You can do the following:

    1. Leave your import as from generic_functions import *
    2. Run flake8 as flake8 --ignore=F405 file.py. I really don't know why # noqa doesn't work, but --ignore does.
    3. Test the rest of possible errors with pylint. Pylint is able to determine that <function> is defined and imported from generic_functions.