@@ -109,12 +109,12 @@ def declare_parser(
109109PARSER_PROTOTYPE_KEYWORD_HELPER : Final [str ] = libclinic .normalize_snippet ("""
110110 static PyObject *
111111 {c_basename}_parse_args({self_type}{self_name}, PyObject *const *args,
112- Py_ssize_t nargs, PyObject *kwargs, PyObject *kwnames)
112+ Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
113113""" )
114114PARSER_PROTOTYPE_KEYWORD___INIT___HELPER : Final [str ] = libclinic .normalize_snippet ("""
115115 static int
116116 {c_basename}_parse_args({self_type}{self_name}, PyObject *const *args,
117- Py_ssize_t nargs, PyObject *kwargs, PyObject *kwnames)
117+ Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
118118""" )
119119PARSER_PROTOTYPE_VARARGS : Final [str ] = libclinic .normalize_snippet ("""
120120 static PyObject *
@@ -718,13 +718,6 @@ def parse_general(self, clang: CLanguage) -> None:
718718 self .declarations += "\n PyObject * const *fastargs;"
719719 if has_optional_kw :
720720 self .declarations += (
721- "\n Py_ssize_t nkw = 0;"
722- "\n if (kwnames != NULL) {{"
723- "\n nkw = PyTuple_GET_SIZE(kwnames);"
724- "\n }}"
725- "\n else if (kwargs != NULL) {{"
726- "\n nkw = PyDict_GET_SIZE(kwargs);"
727- "\n }}"
728721 "\n Py_ssize_t noptargs = %s + nkw - %d;"
729722 % (nargs , self .min_pos + self .min_kw_only ))
730723 unpack_args = 'args, nargs, kwargs, kwnames'
@@ -912,7 +905,9 @@ def handle_new_or_init(self) -> None:
912905 '{{' ,
913906 ' return {c_basename}_parse_args({self_name}, '
914907 '_PyTuple_CAST(args)->ob_item,' ,
915- ' PyTuple_GET_SIZE(args), kwargs, NULL);' ,
908+ ' PyTuple_GET_SIZE(args),' ,
909+ ' kwargs ? PyDict_GET_SIZE(kwargs) : 0,' ,
910+ ' kwargs, NULL);' ,
916911 '}}' ,
917912 ])
918913 return
@@ -1178,8 +1173,9 @@ def emit(text: str, indent: int = 4) -> None:
11781173 if (self == NULL) {{
11791174 return NULL;
11801175 }}
1181- int _result = {c_basename}_parse_args(self,
1182- args, nargs, NULL, kwnames);
1176+ int _result = {c_basename}_parse_args(self, args, nargs,
1177+ kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
1178+ NULL, kwnames);
11831179 if (_result != 0) {{
11841180 Py_DECREF(self);
11851181 return NULL;
@@ -1189,8 +1185,9 @@ def emit(text: str, indent: int = 4) -> None:
11891185 """ )
11901186 else :
11911187 emit ("""
1192- return {c_basename}_parse_args(_PyType_CAST(type), args,
1193- nargs, NULL, kwnames);
1188+ return {c_basename}_parse_args(_PyType_CAST(type), args, nargs,
1189+ kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
1190+ NULL, kwnames);
11941191 """ )
11951192
11961193 if emitted_fast_path :
0 commit comments