Skip to content

# isort: off does not honor import statements but does honor import from statements #2528

@hunterhogan

Description

@hunterhogan

Using the files in ufoLib2/tests,

Run

isort --skip-gitignore --check-only --diff tests

# isort: off not applied serde/test_json.py

Code snippet

import ufoLib2.objects


# isort: off
pytest.importorskip("cattrs")


import ufoLib2.serde.json  # noqa: E402

# isort: off not applied serde/test_msgpack.py

Code snippet

import ufoLib2.objects


# isort: off
pytest.importorskip("cattrs")
pytest.importorskip("msgpack")


import msgpack  # type: ignore  # noqa


import ufoLib2.serde.msgpack  # noqa: E402

# isort: off is applied test_converters.py

Code snippet

from ufoLib2.objects.info import (
    GaspBehavior,
    ...
    WoffMetadataVendor,
)


# isort: off
cattrs = pytest.importorskip("cattrs")
from ufoLib2.converters import register_hooks, structure, unstructure  # noqa: E402

~ ast.Import vs ast.ImportFrom

It seems that the command comment affects objects that would be parsed as ast.ImportFrom objects, but does not affect objects that would be parsed as ast.Import objects.

We stumbled across this while updating multiple files in this PR.

#2239 has some discussions about # isort: off, but I think it's a different issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions