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

Explicit relative imports aren't processed correctly #23

Closed alex closed 10 years ago

alex commented 10 years ago

The following code:

from __future__ import absolute_import, division, print_function

import binascii

import pretend

import pytest

import six

from cryptography.exceptions import (
    AlreadyFinalized, InvalidSignature, _Reasons
)
from cryptography.hazmat.backends.interfaces import CMACBackend
from cryptography.hazmat.primitives.ciphers.algorithms import (
    AES, ARC4, TripleDES
)
from cryptography.hazmat.primitives.cmac import CMAC

from ..backends.test_multibackend import DummyCMACBackend
from ...utils import (
    load_nist_vectors, load_vectors_from_file, raises_unsupported_algorithm
)

Results in the following warnings:

./tests/hazmat/primitives/test_cmac.py:33:1: I100 Imports statements are in the wrong order. from backends.test_multibackend should be before from cryptography.hazmat.primitives.cmac
alex commented 10 years ago

The issue is specifically with application-import-names.

alex commented 10 years ago

Here's a more minimal reproducer:

$ cat t.py
from cryptography import CMAC

from .backends import DummyCMACBackend
$ cat tox.ini
[flake8]
application-import-names = cryptography
$ flake8 --select='I' t.py
t.py:3:1: I100 Imports statements are in the wrong order. from backends should be before from cryptography
public commented 10 years ago

Should the correct order be

from . import N
from .. import M

from .X import N
from ..X import M

from .Y import N
from ..Y import M

or

from . import N
from .X import N
from .Y import N

from .. import M
from ..X import M
from ..Y import M

?

alex commented 10 years ago

The latter, but no newline.

public commented 10 years ago

Good that's much easier to implement :)