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

Correct sort order raises error #3

Closed heston closed 10 years ago

heston commented 10 years ago

I have the following imports at the top of one of my files:

from collections import OrderedDict, namedtuple
import datetime

import coffin.template.loader
from django.core import validators
from django.utils.functional import SimpleLazyObject, cached_property

import lib.forms
import lib.models

However, when I run flake8 on it, I get the following warning:

my_file.py:4:1: I100 Imports are in the wrong order
import coffin.template.loader
^

This looks lexigraphically sorted to me, and coffin is certainly in my site-packages.

Also, I would expect to see a warning for line 6, since cached_property should sort before SimpleLazyObject according to the Google Styleguide ("imports should be sorted lexicographically, ignoring case").

public commented 10 years ago

Hey @heston. We've made quite a lot of changes to our desired style since you filed this issue.

We are much less close to the Google style guide now and are more strict about some sections it is vague on. I need to update the README now we've stabilised a bit but if you look here https://github.com/public/flake8-import-order/blob/master/tests/test_cases/complete.py you can see our ideal example ordering.

public commented 10 years ago

The "correct" order as of 0.4 is this

import datetime
from collections import OrderedDict, namedtuple

import coffin.template.loader

from django.core import validators
from django.utils.functional import SimpleLazyObject, cached_property

import lib.forms
import lib.models
meastman commented 9 years ago

The "correct" import order mentioned in the previous comment is in no way "correct". The Google style guide says "imports should be sorted lexicographically, ignoring case, according to each module's full package path". collections comes before datetime (and both in stdlib). The Google style guide does not differentiate between from foo import bar and import foo for grouping like this checker does.

meastman commented 9 years ago

Since I couldn't reopen this issue, I opened #26