PyCQA / flake8-import-order

Flake8 plugin that checks import order against various Python Style Guides
GNU Lesser General Public License v3.0
278 stars 72 forks source link

Support aliases #33

Closed leebrooks0 closed 9 years ago

leebrooks0 commented 9 years ago

I am using Google style imports:

from django.contrib.auth import models as auth
from django.contrib.auth import hashers

Your linter complains about this and says I should swap the order around, but I am using another tool isort to do the sorting, so obviously one way or the other is the correct way, I am not sure which way it is?

i.e. is your linter correct to complain and isort has sorted incorrectly, or is isort correct in this scenario and your linter has picked up a false positive?

public commented 9 years ago

According to the Google style guide

Within each grouping, imports should be sorted lexicographically, ignoring case, according to each module's full package path.

AIUI the "full package path" is basically the __name__ of it. (Ignoring the part where this can vary depending on run-time configuration such as sys.path.) For from django.contrib.auth import models as auth this is django.contrib.auth.models and this is the sort key is used in this plugin.

I would be willing to entertain alternative interpretations of this clause though :) For example this plugin already makes the decision not to ignore case in the import order as to avoid ambiguity.