@@ -55,6 +55,7 @@ static size_t method_cache_collisions = 0;
55
55
/* alphabetical order */
56
56
_Py_IDENTIFIER (__abstractmethods__ );
57
57
_Py_IDENTIFIER (__class__ );
58
+ _Py_IDENTIFIER (__class_getitem__ );
58
59
_Py_IDENTIFIER (__delitem__ );
59
60
_Py_IDENTIFIER (__dict__ );
60
61
_Py_IDENTIFIER (__doc__ );
@@ -2694,8 +2695,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
2694
2695
Py_DECREF (tmp );
2695
2696
}
2696
2697
2697
- /* Special-case __init_subclass__: if it's a plain function,
2698
- make it a classmethod */
2698
+ /* Special-case __init_subclass__ and __class_getitem__:
2699
+ if they are plain functions, make them classmethods */
2699
2700
tmp = _PyDict_GetItemId (dict , & PyId___init_subclass__ );
2700
2701
if (tmp != NULL && PyFunction_Check (tmp )) {
2701
2702
tmp = PyClassMethod_New (tmp );
@@ -2708,6 +2709,18 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
2708
2709
Py_DECREF (tmp );
2709
2710
}
2710
2711
2712
+ tmp = _PyDict_GetItemId (dict , & PyId___class_getitem__ );
2713
+ if (tmp != NULL && PyFunction_Check (tmp )) {
2714
+ tmp = PyClassMethod_New (tmp );
2715
+ if (tmp == NULL )
2716
+ goto error ;
2717
+ if (_PyDict_SetItemId (dict , & PyId___class_getitem__ , tmp ) < 0 ) {
2718
+ Py_DECREF (tmp );
2719
+ goto error ;
2720
+ }
2721
+ Py_DECREF (tmp );
2722
+ }
2723
+
2711
2724
/* Add descriptors for custom slots from __slots__, or for __dict__ */
2712
2725
mp = PyHeapType_GET_MEMBERS (et );
2713
2726
slotoffset = base -> tp_basicsize ;
0 commit comments