Skip to content

E1136: False positive when used with typing (mypy) patterns #3979

@ssbarnea

Description

@ssbarnea

Apparently even the master branch code does not yet play well with a common pattern used to add type hints. The linked example is not unique, the same pattern can be seen in many places.

While adding # pylint: disable=unsubscriptable-object can be used as a temporary workaround, it worth creating a bug as the more people will be adopting type hints, the more such problems we will face.

import os
from typing import TYPE_CHECKING, Any, Union

if TYPE_CHECKING:
    BasePathLike = os.PathLike[Any] # <-- that is where pylint identifies E1136
else:
    BasePathLike = os.PathLike

foo : Union[str, BasePathLike] = "bar"

Current behavior

example.py:5:19: E1136: Value 'os.PathLike' is unsubscriptable (unsubscriptable-object)

Expected behavior

Pass the linting as the code below is correct.

pylint --version output

2.6.0 and master, on python 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions