Comment 5 for bug 1589186

Revision history for this message
asmeurer (asmeurer) wrote :

The problem is that pyflakes treats imports like variable assignments, but they aren't quite like that. If you write

a = func()

and then never use a, pyflakes is right to tell you that a is never used, because you could just as well have written

func()

without any assignment. But "import scipy.optimize" is the only way to load the scipy.optimize module (it isn't loaded with "import scipy" for performance purposes). So the purpose of the line is to load a module, but it also happens to load a name into the namespace.

Secondly, it's best practice to import scipy and numpy as sp and np, respectively.

> and `scipy` on line 3 being an implicit import of `scipy`.

I don't think that's an error. Python explicitly runs the top-level __init__.py and puts the module name in the namespace. For instance, this code works just fine

import numpy.linalg
numpy.array