Skip to content

Commit 669a69c

Browse files
committed
Clean up _parse_init_args keyword handling
Drop the empty if (!kwargs) fast-path branch and give the defensive duplicate-'data' check a proper error message instead of returning -1 without setting an exception.
1 parent 4a6136d commit 669a69c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/_xxhash.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,7 @@ _parse_init_args(PyObject *args, PyObject *kwargs,
730730
{
731731
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
732732

733-
if (!kwargs) {
734-
/* fast path: no keywords */
735-
} else {
733+
if (kwargs) {
736734
Py_ssize_t pos = 0;
737735
PyObject *key, *val;
738736
while (PyDict_Next(kwargs, &pos, &key, &val)) {
@@ -776,7 +774,11 @@ _parse_init_args(PyObject *args, PyObject *kwargs,
776774
if (kwargs) {
777775
PyObject *val = PyDict_GetItemString(kwargs, "data");
778776
if (val) {
779-
if (*data_obj) return -1; /* unreachable, caught above */
777+
if (*data_obj) {
778+
PyErr_Format(PyExc_TypeError,
779+
"%s() got multiple values for argument 'data'", funcname);
780+
return -1;
781+
}
780782
*data_obj = val;
781783
}
782784
val = PyDict_GetItemString(kwargs, "seed");

0 commit comments

Comments
 (0)