Skip to content

Commit

Permalink
Play with native generics
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed May 8, 2024
1 parent e7aec87 commit 172dc80
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,8 @@ generic_init_subclass(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
static PyObject *
generic_class_getitem(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{
return call_typing_args_kwargs("_generic_class_getitem", cls, args, kwargs);
return Py_GenericAlias(cls, args);
// return call_typing_args_kwargs("_generic_class_getitem", cls, args, kwargs);
}

PyObject *
Expand All @@ -1886,14 +1887,14 @@ _Py_subscript_generic(PyThreadState* unused, PyObject *params)
PyErr_SetString(PyExc_SystemError, "Cannot find Generic type");
return NULL;
}
PyObject *args[2] = {(PyObject *)interp->cached_objects.generic_type, params};
PyObject *result = call_typing_func_object("_GenericAlias", args, 2);
// PyObject *args[2] = {(PyObject *)interp->cached_objects.generic_type, params};
PyObject *result = Py_GenericAlias((PyObject *)interp->cached_objects.generic_type, params);
Py_DECREF(params);
return result;
}

static PyMethodDef generic_methods[] = {
{"__class_getitem__", (PyCFunction)(void (*)(void))generic_class_getitem,
{"__class_getitem__", Py_GenericAlias,
METH_VARARGS | METH_KEYWORDS | METH_CLASS,
generic_class_getitem_doc},
{"__init_subclass__", (PyCFunction)(void (*)(void))generic_init_subclass,
Expand Down

0 comments on commit 172dc80

Please sign in to comment.