fisadev / vim-isort

Vim plugin to sort python imports using https://github.com/timothycrosley/isort
MIT License
219 stars 32 forks source link

Fix #37 - Support isort >= 5 #38

Closed ziima closed 3 years ago

ziima commented 4 years ago

Fix for the change of API in isort.

ziima commented 3 years ago

Fixed also loading of isort config.

fisadev commented 3 years ago

Great! I'll review it later today, but thanks in advance :)

fisadev commented 3 years ago

It has a bug, it won't work when no isort is present (will raise an ImportError). This is because of this structure:

try:
    # import isort 5
except ImportError:
    # import isort older
except ImportError:
    # handle no insort

If the bit that tries to import an older isort fails, the second except won't be used. In python, the excepts only apply to the code from the try block, they don't apply to other except blocks. If you want to catch a possible exception inside an except block, you need a new try/except, like this:

try:
    # import isort 5
except ImportError:
    try:
        # import isort older
    except ImportError:
        # handle no insort
ziima commented 3 years ago

:facepalm: Fixed.

fisadev commented 3 years ago

Merged! thanks for the fix :)