MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetClassName

Function GetClassName

tensorflow/python/util/util.cc:93–109  ·  view source on GitHub ↗

Equivalent to Python's 'o.__class__.__name__' Note that '__class__' attribute is set only in new-style classes. A lot of tensorflow code uses __class__ without checks, so it seems like we only support new-style classes.

Source from the content-addressed store, hash-verified

91// A lot of tensorflow code uses __class__ without checks, so it seems like
92// we only support new-style classes.
93StringPiece GetClassName(PyObject* o) {
94 // __class__ is equivalent to type() for new style classes.
95 // type() is equivalent to PyObject_Type()
96 // (https://docs.python.org/3.5/c-api/object.html#c.PyObject_Type)
97 // PyObject_Type() is equivalent to o->ob_type except for Py_INCREF, which
98 // we don't need here.
99 PyTypeObject* type = o->ob_type;
100
101 // __name__ is the value of `tp_name` after the last '.'
102 // (https://docs.python.org/2/c-api/typeobj.html#c.PyTypeObject.tp_name)
103 StringPiece name(type->tp_name);
104 size_t pos = name.rfind('.');
105 if (pos != StringPiece::npos) {
106 name.remove_prefix(pos + 1);
107 }
108 return name;
109}
110
111string PyObjectToString(PyObject* o) {
112 if (o == nullptr) {

Callers 2

PyObjectToStringFunction · 0.70
SameNamedtuplesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected