Skip to content

Commit

Permalink
Use PyType_Check() instead of direct comparison with PyType_Type
Browse files Browse the repository at this point in the history
…pointer.

Context:

* pybind/pybind11#4427 (comment)

> I don't think your logic ... is actually correct? I don't think it would handle metaclasses right.

PiperOrigin-RevId: 498690703
  • Loading branch information
rwgk committed Jan 1, 2023
1 parent 53d827e commit ef64abf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clif/python/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ PyObject* ImportFQName(const std::string& full_class_name,

// py.__class__.__name__
const char* ClassName(PyObject* py) {
if (Py_TYPE(py) == &PyType_Type) {
if (PyType_Check(py)) {
return reinterpret_cast<PyTypeObject*>(py)->tp_name;
}
return Py_TYPE(py)->tp_name;
}

// type(py) renamed from {classobj, instance, type, class X}
const char* ClassType(PyObject* py) {
if (Py_TYPE(py) == &PyType_Type) {
if (PyType_Check(py)) {
return "class";
}
return "instance";
Expand Down

0 comments on commit ef64abf

Please sign in to comment.