pythonpython-importstatic-analysispep8

Import order coding standard


PEP8 suggests that:

Imports should be grouped in the following order:

  1. standard library imports
  2. related third party imports
  3. local application/library specific imports

You should put a blank line between each group of imports.

Is there a way to check if the standard is violated anywhere in the package using static code analysis tools, like pylint, pyflakes, pychecker, pep8?


Example of violation:

from my_package import my_module
from django.db import models
import os

Correct way to import:

import os

from django.db import models

from my_package import my_module

Solution

  • The current version of pylint now does this, and reports it as error class C0411.