I recently upgraded versions of pylint, a popular Python style-checker.
It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying the full package path.
The new error message is W0403.
W0403: Relative import %r, should be %r
Used when an import relative to the package directory is detected.
Example
For example, if my packages are structured like this:
/cake
/__init__.py
/icing.py
/sponge.py
/drink
and in the sponge package I write:
import icing
instead of
import cake.icing
I will get this error.
While I understand that not all Pylint messages are of equal importance, and I am not afraid to dismiss them, I don't understand why such a practice is considered a poor idea.
I was hoping someone could explain the pitfalls, so I could improve my coding style rather than (as I currently plan to do) turning off this apparently spurious warning.
import .icinginstead offrom . import icing– Jack Oct 14 '15 at 01:43Relative imports must always use
from <> import;import <>is always absolute. Of course, absolute imports can usefrom <> importby omitting the leading dots. The reasonimport .foois prohibited is because afterimport XXX.YYY.ZZZthenXXX.YYY.ZZZis usable in an expression. But
– A.Wan Nov 13 '15 at 19:50.moduleYis not usable in an expression.