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

Weird I202 error #181

Closed sergeyklay closed 3 years ago

sergeyklay commented 3 years ago

Hello,

It seems flake8-import-order false positive triggered with such code

import pytest

from django.core.management import call_command

fixtures = ['settings', 'sites']

@pytest.fixture(autouse=True)
def django_db_setup(django_db_setup, django_db_blocker):
    """Populate Django test database with pytest fixtures."""
    with django_db_blocker.unblock():
        call_command('loaddata', *[f'{fixture}.json' for fixture in fixtures])

I202 Additional newline in a group of imports. 'from django.core.management import call_command' is identified as Third Party and 'import pytest' is identified as Third Party. from django.core.management import call_command ^

Configuration from setup.cfg:

[flake8]
import-order-style = smarkets

Versions:

$ flake8 --version
3.9.1 (flake8-blind-except: 0.2.0, flake8_builtins: 1.5.2, import-order: 0.18.1, mccabe: 0.6.1, pycodestyle: 2.7.0, pyflakes: 2.3.1) CPython 3.9.4 on Darwin

Is this intentional?

sigmavirus24 commented 3 years ago

I don't understand how this is a false positive? Are you working on pytest the project? If not, are pytest and django not both 3rd party modules to your code and/or tests?

sigmavirus24 commented 3 years ago

To be clear, flake8-import-order is detecting both pytest and django as 3rd party libraries. Those should be in a single block like so:

import pytest
from django.core.management import call_command

No newline between the imports

sergeyklay commented 3 years ago

@sigmavirus24 Hm... Frankly speaking flake8-import-order saying nothing about something like

import os

from django.core.wsgi import get_wsgi_application

and I was probably misled about how smarkets style works. Now I got it. Thank you.

sigmavirus24 commented 3 years ago

os is standard library so there should be an extra newline there

sergeyklay commented 3 years ago

Yeah, now I got it. Thank you!