Skip to content

Cannot catch double import in TYPE_CHECKING block #12270

@beskep

Description

@beskep

command: ruff check --select TCH,I,F
version: 0.5.1

code:

from decimal import Decimal  # I001: import block un-sorted
from decimal import Decimal  # F811: redefinition
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from decimal import Decimal  # reimport, but no error


def fn():
    value: Decimal  # noqa: F842

I often import the same bunch of modules by snippet after TCH creates TYPE_CHECKING block.
ruff --fix deletes the second line above and keeps the first line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions