PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.52k stars 582 forks source link

isort removed my # noqa comment #359

Closed jacobsvante closed 8 years ago

jacobsvante commented 9 years ago

As you can see below noqa comment has disappeared for the second import entry. How can I avoid this?

(My noqa comment is for flake8)

# cat fields.py

from wtforms_components import (  # noqa
    ColorField,
    DateField,
    DateIntervalField,
    DateTimeField,
    DateTimeIntervalField,
    DecimalField,
    DecimalIntervalField,
    DecimalSliderField,
    EmailField,
    FloatIntervalField,
    GroupedQuerySelectField,
    IntegerField,
    IntegerSliderField,
    IntIntervalField,
    PassiveHiddenField,
    PhoneNumberField,
    SearchField,
    SelectField,
    SelectMultipleField as SelectMultipleField_,
    SplitDateTimeField,
    StringField,
    TimeField,
    WeekDaysField,
)

# isort fields.py && cat fields.py

from wtforms_components import SelectMultipleField as SelectMultipleField_  # noqa
from wtforms_components import (ColorField, DateField, DateIntervalField,
                                DateTimeField, DateTimeIntervalField,
                                DecimalField, DecimalIntervalField,
                                DecimalSliderField, EmailField,
                                FloatIntervalField, GroupedQuerySelectField,
                                IntegerField, IntegerSliderField,
                                IntIntervalField, PassiveHiddenField,
                                PhoneNumberField, SearchField, SelectField,
                                SplitDateTimeField, StringField, TimeField,
                                WeekDaysField)
timothycrosley commented 8 years ago

I'll look into this, thanks for reporting! Sorry for the long wait, been heads down working on hug: https://github.com/timothycrosley/hug

~Timothy

jacobsvante commented 8 years ago

No worries at all. Looks like an interesting project!

timothycrosley commented 8 years ago

Hi @jmagnusson I think the best way to avoid this is to add isort:skip to that single import to have handled special for isort (just as it is for flake8) it's very difficult for isort to know if a comment was meant for a group or single import, and even harder for it to keep track of where to place it. It took quite a while for isort to attempt to handle comments at all (originally it would strip them all!) It's better now, but I'm not sure how to handle this particular case other then to tell isort not to mess with the import. I hope this is helpful.

Thanks!

~Timothy