Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing PyMyType_Check methods with Python C API?

All the Python-provided types have a check method (i.e., PyList_Check) that allows you to check if an arbitrary PyObject* is actually a specific type.

How can I implement this for my own types? I haven't found anything good online for this, though it seems like a pretty normal thing to want to do.

Also, maybe I'm just terrible at looking through large source trees, but I cannot for the life of me find the implementation of PyList_Check or any of it's companions in the Python (2.5) source.

like image 499
Paul D. Avatar asked Mar 26 '26 23:03

Paul D.


1 Answers

That's because they're macros that use deep magic. Save yourself a bit of headache and use PyObject_IsInstance() instead.

like image 188
Ignacio Vazquez-Abrams Avatar answered Mar 29 '26 12:03

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!