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

Function MappingKeys

tensorflow/python/util/util.cc:860–873  ·  view source on GitHub ↗

Work around a writable-strings warning with Python 2's PyMapping_Keys macro, and while we're at it give them consistent behavior by making sure the returned value is a list. As with PyMapping_Keys, returns a new reference. On failure, returns nullptr.

Source from the content-addressed store, hash-verified

858//
859// On failure, returns nullptr.
860PyObject* MappingKeys(PyObject* o) {
861#if PY_MAJOR_VERSION >= 3
862 return PyMapping_Keys(o);
863#else
864 static char key_method_name[] = "keys";
865 Safe_PyObjectPtr raw_result(PyObject_CallMethod(o, key_method_name, nullptr));
866 if (PyErr_Occurred() || raw_result.get() == nullptr) {
867 return nullptr;
868 }
869 return PySequence_Fast(
870 raw_result.get(),
871 "The '.keys()' method of a custom mapping returned a non-sequence.");
872#endif
873}
874
875PyObject* Flatten(PyObject* nested, bool expand_composites) {
876 PyObject* list = PyList_New(0);

Callers 3

TFE_Py_EncodeArgHelperFunction · 0.85
MappingValueIteratorMethod · 0.85
SetDifferentKeysErrorFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected