Skip to content

Commit ef64abf

Browse files
committed
Use PyType_Check() instead of direct comparison with PyType_Type 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
1 parent 53d827e commit ef64abf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clif/python/runtime.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ PyObject* ImportFQName(const std::string& full_class_name,
157157

158158
// py.__class__.__name__
159159
const char* ClassName(PyObject* py) {
160-
if (Py_TYPE(py) == &PyType_Type) {
160+
if (PyType_Check(py)) {
161161
return reinterpret_cast<PyTypeObject*>(py)->tp_name;
162162
}
163163
return Py_TYPE(py)->tp_name;
164164
}
165165

166166
// type(py) renamed from {classobj, instance, type, class X}
167167
const char* ClassType(PyObject* py) {
168-
if (Py_TYPE(py) == &PyType_Type) {
168+
if (PyType_Check(py)) {
169169
return "class";
170170
}
171171
return "instance";

0 commit comments

Comments
 (0)