Skip to content

Import headings in blocks lead to check errors #1301

@mir06

Description

@mir06

When using import_heading for a section and the import is not at module level the isort-ed code is now perfectly formatted (#1290) but it does not pass the check anymore.

Here's a simple example for demonstration

import isort
code = """
try: 
    import logging 
        from os import abc, path 
    except ImportError: 
        pass
"""
extra_config = {"import_heading_stdlib": "stdlib"}
# checking code leads to error
isort.check_code(isort.code(code, **extra_config), **extra_config)
ERROR:  Imports are incorrectly sorted and/or formatted.
False
# the fixes are applied once
isort.code(code, **extra_config) == isort.code(isort.code(code, **extra_config), **extra_config)
True

When running isort on the command-line it says that the file is fixed but nothing is changed and this leads to an infinite loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions