>>> class Generic:
... def __class_getitem__(cls, item, *args, **kwargs):
... return (cls, item, args, kwargs)
...
>>> Generic[int, str]
(<class '__main__.Generic'>, (<class 'int'>, <class 'str'>), (), {})
>>>>> class Generic:
..... def __class_getitem__(cls, item, *args, **kwargs):
..... return (cls, item, args, kwargs)
.....
>>>>> Generic[int, str]
<class 'type'>
Feature
CPython-side
RustPython-side
Python Documentation
tp_newimplementation source: https://github.com/python/cpython/blob/fa919fdf2583bdfead1df00e842f24f30b2a34bf/Objects/typeobject.c#L2707-L2720