I think that both partial and partialmethod can be realized in pure c. This idea is to expose them in capi:
bool PyPartial_Check(PyObject* obj): return whether the object is an instance of partialbool PyPartialMethod_Check(PyObject* obj): return whether the object is an instance of partialmethodPyObject* PyPartial_GetFunc(PyObject* obj): return thefuncattribute of a partial object (need check before)PyObject* PyPartialMethod_GetFunc(PyObject* obj): return thefuncattribute of a partialmethod object (need check before)PyObject* PyPartial_GetArgs(PyObject* obj): return theargsattribute of a partial object (need check before)PyObject* PyPartialMethod_GetArgs(PyObject* obj): return theargsattribute of a partialmethod object (need check before)PyObject* PyPartial_GetKwargs(PyObject* obj): return thekwargsattribute of a partial object (need check before)PyObject* PyPartialMethod_GetKwargs(PyObject* obj): return thekwargsattribute of a partialmethod object (need check before)
If they are exposed in capi user don’t need to import the hole functools and the checking and getting can be faster.