isort 5.5.2 mangles lines that happens to start with `from`

Created on 18 Sep 2020  路  5Comments  路  Source: PyCQA/isort

e.g.:

    raise SomeException("Blah") \
        from exceptionsInfo.popitem()[1]

It transforms it into the gibberish:

    raise SomeException("Blah") \
        from exceptionsInfo.popitem import [1]

isort 4.x didn't do this.

bug

Most helpful comment

A 5.5.3 hot fix release has just been completed to PyPI that fixes this issue. Confirmed that Python's grammar only allows from to be used for imports, within raise statements, and within yield statements (yield from). Considerable additional testing has been placed around these usages to make sure isort does not mistake them on line continuations as import statements.

Thanks!

~Timothy

All 5 comments

@wadetregaskis-linkedin that's a nasty bug! I'll make sure the isort project has a release soon that resolves it and adds additional test cases to ensure it never happens again.

@anirudnits I'm a bit confused about your example? One of the biggest headline features of isort 5 is its ability to sort imports anywhere they are within a file, largely safely: https://pycqa.github.io/isort/docs/major_releases/introducing_isort_5/#sort-imports-anywhere if isort is simply sorting the second import statement that's good! If you encountered any sort of incorrect syntax produced, that of course would be a major bug like the one @wadetregaskis-linkedin raised

Thanks!

~Timothy

For anyone that runs into this before it is resolved, one option would be to utilize action comments to skip the offending section, since these should be very rare: https://pycqa.github.io/isort/docs/configuration/action_comments/

@timothycrosley sorry my bad :(

@anirudnits No worries! Just wanted to make sure there wasn't an additional error case of this proportion

A 5.5.3 hot fix release has just been completed to PyPI that fixes this issue. Confirmed that Python's grammar only allows from to be used for imports, within raise statements, and within yield statements (yield from). Considerable additional testing has been placed around these usages to make sure isort does not mistake them on line continuations as import statements.

Thanks!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghickman picture ghickman  路  3Comments

darkclouder picture darkclouder  路  3Comments

pawamoy picture pawamoy  路  3Comments

jack1142 picture jack1142  路  3Comments

donjar picture donjar  路  3Comments