| 22 | namespace functional { |
| 23 | |
| 24 | void FunctionSchema::ReportKwargsError(PyObject* kwargs, size_t nargs) const { |
| 25 | PyObject *key = nullptr, *value = nullptr; |
| 26 | Py_ssize_t pos = 0; |
| 27 | |
| 28 | while (PyDict_Next(kwargs, &pos, &key, &value)) { |
| 29 | if (!PyStringCheck(key)) { THROW(TypeError) << def_->name << "(): keywords must be strings"; } |
| 30 | int64_t index = -1; |
| 31 | const std::string string_key = PyStringAsString(key); |
| 32 | for (int i = 0; i < def_->argument_def.size(); ++i) { |
| 33 | const auto& arg = def_->argument_def[i]; |
| 34 | if (arg.name == string_key) { |
| 35 | index = i; |
| 36 | break; |
| 37 | } |
| 38 | } |
| 39 | if (index < 0) { |
| 40 | THROW(TypeError) << def_->name << "(): got an unexpected keyword argument '" << string_key |
| 41 | << "'"; |
| 42 | } |
| 43 | if (index < nargs) { |
| 44 | THROW(TypeError) << def_->name << "(): got multiple values for argument '" << string_key |
| 45 | << "'"; |
| 46 | } |
| 47 | } |
| 48 | THROW(TypeError) << def_->name << "(): kwargs unknown error"; |
| 49 | } |
| 50 | |
| 51 | // The argument parsing refers to the implementation of Pytorch. |
| 52 | bool FunctionSchema::Parse(PyObject* args, PyObject* kwargs, PythonArg* parsed_args, |
nothing calls this directly
no test coverage detected