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

issue with relative imports #24

Closed adrianandreias closed 9 years ago

adrianandreias commented 9 years ago

After updating to 2014-10-29 version I started getting lots of:

I201 Missing newline before sections or imports.

For absolute imports followed by relative imports:

from myproject.app.tests import UserFactory
from .tests import SomeClass

I have these settings defined in tox.ini:

import-order-style=google
application-import-names=myproject,myproject2

Anyone else getting changed behavior with the 2014-10-29 release?

public commented 9 years ago

Previously we handled relative imports incorrectly. I've improved this behaviour but a side effect of that is that it now expects a new line between the absolute application imports and the relative ones.

Arguably this behaviour is undesirable though so I can probably be convinced to make it ignore that situation.

Any opinions @alex?

adrianandreias commented 9 years ago

Hi,

I don't see this rule here: https://google-styleguide.googlecode.com/svn/trunk/pyguide.html?showone=Imports_formatting#Imports_formatting

And I never heard about separate groups for absolute imports and relative imports, just stdlib import group, 3rd parties group and local group. And with absolute imports first in each group and relative imports last in each group.

public commented 9 years ago

I would be fine with disabling that warning entirely in Google mode :)

adrianandreias commented 9 years ago

PEP8 also doen't talk about separate groups for absolute and relative imports: http://legacy.python.org/dev/peps/pep-0008/#imports

but just for the stdlib, 3rd party and local, just like Google guidelines.

Is there a way I can disable this behavior or you mean a new release is needed for this?

Thanks ;)

alex commented 9 years ago

I do a separate group for relative and absolute, so this is fine with me :-)

On Wed, Nov 5, 2014, 9:48 AM Adrian Andreias notifications@github.com wrote:

PEP8 also doen't talk about separate groups for absolute and relative imports: http://legacy.python.org/dev/peps/pep-0008/#imports

but just for the stdlib, 3rd party and local, just like Google guidelines.

Is there a way I can disable this behavior or you mean a new release is needed for this?

Thanks ;)

— Reply to this email directly or view it on GitHub https://github.com/public/flake8-import-order/issues/24#issuecomment-61801936 .

public commented 9 years ago

@adrianandreias You can easily exclude the the I201 error entirely in flake8. Just add --exclude=I201 to your command, or add it to setup.cfg or tox.ini.

adrianandreias commented 9 years ago

Yes, but then I'll no longer have validation against the 3 PEP8 defined import groups: stdlib, 3rd party and local.

meshy commented 9 years ago

Yes, but then I'll no longer have validation against the 3 PEP8 defined import groups: stdlib, 3rd party and local.

:+1:

adrianandreias commented 9 years ago

Yeah, I'm stuck with an older version to overcome this. I still don't understand why @public and @alex are using a standard of their own. Standard that is not specified in PEP8 nor in Google standards.

meshy commented 9 years ago

Perhaps this could be overcome by having more fine-grained configuration options... that way, people can use their own standards by diverging from the default.

public commented 9 years ago

On pyca/cryptography we wanted to avoid ambiguity in the ordering so we extended it ourselves. I would like to have a more compatible mode in this though.