MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ReportKwargsError

Method ReportKwargsError

oneflow/api/python/functional/python_arg_parser.cpp:24–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace functional {
23
24void 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.
52bool FunctionSchema::Parse(PyObject* args, PyObject* kwargs, PythonArg* parsed_args,

Callers

nothing calls this directly

Calls 3

PyStringCheckFunction · 0.85
PyStringAsStringFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected