Skip to content

Pylint reports ungrouped-imports for TYPE_CHECKING imports #3382

@Martmists-GH

Description

@Martmists-GH

Steps to reproduce

from typing import TYPE_CHECKING
from anyio import run, connect_tcp, create_task_group

if TYPE_CHECKING:
    from typing import List
    from anyio import SocketStream, TaskGroup  # pylint: disable=ungrouped-imports

Remove the pylint: disable comment and it will report ungrouped-imports

Current behavior

ungrouped-imports is reported for any duplicate import sources defined in an if TYPE_CHECKING block, not including the typing module.

Expected behavior

Pylint accepts the syntax as it's common to have certain imports in TYPE_CHECKING if not needed at runtime.

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.8.1 (default, Jan  8 2020, 23:09:20) 
[GCC 9.2.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs reproduction 🔍Need a way to reproduce it locally on a maintainer's machine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions