Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commented Import sorting #1396

Closed
jameswinegar opened this issue Aug 21, 2020 · 5 comments
Closed

Commented Import sorting #1396

jameswinegar opened this issue Aug 21, 2020 · 5 comments
Labels
repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue.

Comments

@jameswinegar
Copy link
Contributor

We've been using isort significantly across projects recently, and we've seen significant improvement in the capabilities.

We have one sticking issue across projects with commented imports. It would be nicer if these commented imports were section aware. Below is our most common example, but it also applies to a strictly commented import as well.

Setup.cfg

[isort]
line_length = 88
known_first_party = apps
known_django = django
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

Before isort

from django.shortcuts import render
from apps.profiler.models import Project
from django.contrib.auth.decorators import login_required
from django.views.generic import (
    # ListView, 
    # DetailView,
    TemplateView,
    # CreateView,
    # View
)

After isort (Actual)

from django.contrib.auth.decorators import login_required
from django.shortcuts import render

from apps.profiler.models import Project

from django.views.generic import TemplateView  # ListView,; DetailView,; CreateView,; View

After isort (Expected)

from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.views.generic import TemplateView  # ListView,; DetailView,; CreateView,; View

from apps.profiler.models import Project
timothycrosley added a commit that referenced this issue Aug 22, 2020
@timothycrosley
Copy link
Member

timothycrosley commented Aug 22, 2020

Hi @jameswinegar,

I'm sorry you are getting that incorrect grouping! I added a test case with the exact code and settings that you shared to the isort regression test suite and am unable to reproduce: ff1ccda.

Is it possible that you encountered this on an older version of isort or that there are additional settings used beyond those shared?

If updating to the latest isort version doesn't fix your issue, posting the output of isort --show-config could help reproduce the issue you are encountering.

Thanks!

~Timothy

@timothycrosley timothycrosley added the repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. label Aug 22, 2020
@jameswinegar
Copy link
Contributor Author

jameswinegar commented Aug 22, 2020

I wasn't able to reproduce either with just the import header.

I have found a different bug when trying to reproduce. For now, let's assume that the original one I tried to articulate is solved.

Given the below isort will not move the django.views.generic section.

from django.contrib.auth.decorators import login_required
from django.shortcuts import render

from apps.profiler.models import Project

from django.views.generic import ( # ListView,; DetailView,; CreateView,; View
    TemplateView,
)

However, with this modification isort will work as planned.

from django.contrib.auth.decorators import login_required
from django.shortcuts import render

from apps.profiler.models import Project

from django.views.generic import ( 
    # ListView,; DetailView,; CreateView,; View
    TemplateView,
)

Config

[isort]
line_length = 88
known_first_party = apps  # change it for the name of your django project
known_django = django
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
include_trailing_comma = True
multi_line_output = 3
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True

@timothycrosley
Copy link
Member

Hi @jameswinegar,

Thanks for digging further into your issue! Using the above example, I was able to add an additional regression test and resolve that issue. It is fixed in develop and will be deployed with release 5.5.0 of isort.

Thanks!

~Timothy

@ndevenish
Copy link
Contributor

Just encountered this issue (semicolon breaking sort), tracked it's cause down and then was pleased to find it's already been fixed!

@timothycrosley
Copy link
Member

This change has just been deployed to PyPI in version 5.5.0

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue.
Projects
None yet
Development

No branches or pull requests

3 participants