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

I202 bug? #145

Closed tvytlx closed 6 years ago

tvytlx commented 6 years ago
$ cat test_import.py
import requests

from b import sth

$ cat b.py
sth = 0

$ flake8 test_import.py
test_import.py:1:1: F401 'requests' imported but unused
test_import.py:3:1: F401 'b.sth' imported but unused
test_import.py:3:1: I202 Additional newline in a section of imports.  ???why

$ flake8 --version
3.5.0 (import-order: 0.16, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.6.3 on Darwin

pep8 says

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.

so there should be a newline between local python module and third-party module.

pgjones commented 6 years ago

You will need to inform flake8 that b is a local or application package, as explained. This is currently the only way this plugin can determine the difference between an application package and a third party package.

In your example the plugin thinks both requests and b are third party and hence should be in the same group without the blank line.