Search code examples
pythonimportpylint

Pyhon module import order relevance, pylint wrong-import-order


Recently I started using pylint to check my python code.

I was surprised to see the following messages:

C: 18, 0: standard import "import anydbm" should be placed before "import numpy as np" (wrong-import-order)
C: 19, 0: standard import "import pickle" should be placed before "import numpy as np" (wrong-import-order)

All the imports are at the top of the script anyway.

Why would it matter in which order I import these modules?

I didn't notice that any of my code was broken when the import order was not optimal (according to pylint). Until now, I have assumed that all modules are independent, but maybe I'm wrong...

In the meantime, I have found this information: Import order coding standard, which seems to confirm my assumption/observation.

Can someone please confirm, that these modules are indeed not related and the import order is relevant only for the cosmetic purpose?


Solution

  • The import order doesn't affect the functionality of your program. But there is a style guide that suggests how you should order them. The wrong-import-order warning just means you didn't follow that.

    But this was already asked and answered elswhere:

    https://stackoverflow.com/a/26804809/660389