Open
Description
Bug description
possibly related to #3488
when a generic class includes a definition of __class_getitem__
, instances created from an annotated class are flagged as "unsubscriptable-object" even when the class itself also includes a __getitem__
method.
Example test.py file:
"""__class_getitem__ test"""
from typing import TypeVar, Generic
T = TypeVar("T")
class Test(Generic[T]):
"""Test class"""
def __class_getitem__(cls, *args):
return super().__class_getitem__(*args)
def __init__(self, iterable):
super().__init__()
self._list: list[T] = list(iterable)
def __getitem__(self, index):
return self._list[index]
t = Test[int]([1, 2, 3])
print(t[1])
Command used
pylint -E test.py
Pylint output
************* Module test
test.py:21:6: E1136: Value 't' is unsubscriptable (unsubscriptable-object)
Expected behavior
the instance t
is subscriptable, so no error should be reported
Pylint version
pylint 3.3.4
astroid 3.3.8
Python 3.9.21 | packaged by conda-forge | (main, Dec 5 2024, 13:47:18)
[Clang 18.1.8 ]
OS / Environment
MacOS, ARM (M1), running Sequoia