py.__class__.__name__
| 30 | |
| 31 | // py.__class__.__name__ |
| 32 | const char* ClassName(PyObject* py) { |
| 33 | /* PyPy doesn't have a separate C API for old-style classes. */ |
| 34 | #if PY_MAJOR_VERSION < 3 && !defined(PYPY_VERSION) |
| 35 | if (PyClass_Check(py)) |
| 36 | return PyString_AS_STRING( |
| 37 | CHECK_NOTNULL(reinterpret_cast<PyClassObject*>(py)->cl_name)); |
| 38 | if (PyInstance_Check(py)) |
| 39 | return PyString_AS_STRING(CHECK_NOTNULL( |
| 40 | reinterpret_cast<PyInstanceObject*>(py)->in_class->cl_name)); |
| 41 | #endif |
| 42 | if (Py_TYPE(py) == &PyType_Type) { |
| 43 | return reinterpret_cast<PyTypeObject*>(py)->tp_name; |
| 44 | } |
| 45 | return Py_TYPE(py)->tp_name; |
| 46 | } |
| 47 | |
| 48 | } // end namespace |
| 49 |