Skip to content

Add skip comment to disable add-modules lines on a per-file basis. #1737

Closed
@mjpieters

Description

@mjpieters
Contributor

I am adding from __future__ import annotations to our project files, automatically, using isort. But, in highly specialised cases such as marshmallow-dataclasses use, I'd like isort to not add that import line.

Right now I can only do so by adding # isort: skip_file to a module where I don't want the extra import to be added automatically.

Could isort perhaps support the following syntax?

# isort: skip: from __future__ import annotations

This would be treated as a add_imports.remove("from __future__ import annotations") action, and you'd have to add this comment high enough in the file to apply before add_imports is processed.

Activity

added a commit that references this issue on Jun 17, 2021

Implemented #1737: Support for using action comments to avoid adding …

timothycrosley

timothycrosley commented on Jun 17, 2021

@timothycrosley
Member

Hi @mjpieters,

Thanks for the great feature suggestion! This has been implemented as 2 new action comments, documented here: https://pycqa.github.io/isort/docs/configuration/action_comments.html#isort-dont-add-imports to skip all adding, or the adding of a particular import to a file. This will be released to PyPI later this week.

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @mjpieters@timothycrosley

      Issue actions

        Add skip comment to disable add-modules lines on a per-file basis. · Issue #1737 · PyCQA/isort