pytype
pytype copied to clipboard
cls not callable inside `__class_getitem__`
import typing
T = typing.TypeVar("T")
class C(typing.Generic[T]):
def __init__(self, arg) -> None:
self.arg = arg
def __class_getitem__(cls, arg):
return cls(arg)
This produces an unexpected error:
File "/home/elt/code/pytype-test/proj/cls_getitem.py", line 10, in __class_getitem__: 'C' object is not callable [not-callable]
However, if I replace cls(arg) with C(arg), the error goes away. This also works in mypy.
A second issue is that it would be nice if the type was considered indexable if it defines __class_getitem__ even if it does not inherit from Generic.