| 498 | } |
| 499 | |
| 500 | std::string CastPyArg2String(PyObject* obj, |
| 501 | const std::string& op_type, |
| 502 | ssize_t arg_pos) { |
| 503 | if (PyObject_CheckString(obj)) { |
| 504 | Py_ssize_t size = 0; |
| 505 | const char* data = nullptr; |
| 506 | data = PyUnicode_AsUTF8AndSize(obj, &size); |
| 507 | return std::string(data, (size_t)size); // NOLINT |
| 508 | } else { |
| 509 | PADDLE_THROW(common::errors::InvalidType( |
| 510 | "%s(): argument (position %d) must be " |
| 511 | "str, but got %s", |
| 512 | op_type, |
| 513 | arg_pos + 1, |
| 514 | ((PyTypeObject*)obj->ob_type)->tp_name)); // NOLINT |
| 515 | } |
| 516 | |
| 517 | return ""; |
| 518 | } |
| 519 | std::string CastPyArg2String(PyObject* obj, |
| 520 | const std::string& op_type, |
| 521 | ssize_t arg_pos, |
no test coverage detected