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"
example.py:5:19: E1136: Value 'os.PathLike' is unsubscriptable (unsubscriptable-object)
Pass the linting as the code below is correct.
2.6.0 and master, on python 3.9
This failed for me too:
from typing import Optional
x: Optional[int]
@ssbarnea thanks for your report. I can reproduce it.
@ajeetdsouza your issue is different from original one and has already been fixed thanks to #3890
This seems to be related to #3951
Which will be fixed with the next astroid update: PyCQA/astroid#885
@cdce8p thank you! I can confirm the bug is fixed. I can no longer reproduce it with current master branches of astroid and pylint.
Most helpful comment
@ssbarnea thanks for your report. I can reproduce it.
@ajeetdsouza your issue is different from original one and has already been fixed thanks to #3890