tweekmonster / impsort.vim

Sort and highlight Python imports in Vim
MIT License
37 stars 6 forks source link

Inconsistent grouping? #15

Closed DanCardin closed 8 years ago

DanCardin commented 8 years ago

So starting with the imports:

import datetime
import dateutil
import flask

I get

import datetime

import dateutil

import flask

Which I'm not sure what's up with that. All three should be 3rd party libs which get grouped together. (plus in getting together this example, I noticed imports by themselves in a file adds an unnecessary newline at the EOF)

Secondarily

from sqlalchemy import and_, not_, or_
from sqlalchemy.orm import aliased

from myapi import db
from myapi.subpackage import models

Correctly sorts by, by doing nothing (including no newline at the EOF), but

from sqlalchemy import and_, not_, or_
from sqlalchemy.orm import aliased

from myapi import db

sorts to (again, newline EOF)

from myapi import db

from sqlalchemy import and_, not_, or_
from sqlalchemy.orm import aliased
tweekmonster commented 8 years ago

Not sure what's up with your first example. This is what I get when I sort them:

import datetime

import flask
import dateutil

Which looks correct to me. datetime is a builtin. The other two are third party, but orphans/loners so are grouped together.

So, your main issue is that scripts that only contain imports shouldn't have a blank line at the end of the file? I think I can fix that easily.

DanCardin commented 8 years ago

Woops, no idea why I said datetime was a third party lib, but it looks like dateutil was an issue with my virtualenv or something because a fresh env fixed it. weird!