Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0872fc

Browse files
committed
vgetargskeywords:
+ Got rid of now-redundant dict typecheck. + Renamed nkwds to nkwlist. Now all the "counting" vrbls have names related to the things they're counting in an obvious way.
1 parent 6fb2635 commit b0872fc

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

Python/getargs.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
10341034
char *formatsave;
10351035
int i, len, nargs, nkeywords;
10361036
char *msg, *ks, **p;
1037-
int nkwds, pos, match, converted;
1037+
int nkwlist, pos, match, converted;
10381038
PyObject *key, *value;
10391039

10401040
assert(args != NULL && PyTuple_Check(args));
@@ -1080,24 +1080,11 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
10801080
format = formatsave;
10811081

10821082
nargs = PyTuple_GET_SIZE(args);
1083+
nkeywords = keywords == NULL ? 0 : PyDict_Size(keywords);
10831084

1084-
/* do a cursory check of the keywords just to see how many we got */
1085-
1086-
nkeywords = 0;
1087-
if (keywords) {
1088-
if (!PyDict_Check(keywords)) {
1089-
PyErr_Format(PyExc_SystemError,
1090-
"%s received when keyword dictionary expected",
1091-
keywords->ob_type->tp_name);
1092-
return 0;
1093-
}
1094-
nkeywords = PyDict_Size(keywords);
1095-
}
1096-
10971085
/* make sure there are no duplicate values for an argument;
10981086
its not clear when to use the term "keyword argument vs.
10991087
keyword parameter in messages */
1100-
11011088
if (keywords) {
11021089
for (i = 0; i < nargs; i++) {
11031090
char *thiskw = kwlist[i];
@@ -1175,14 +1162,14 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
11751162
/* make sure the number of keywords in the keyword list matches the
11761163
number of items in the format string */
11771164

1178-
nkwds = 0;
1165+
nkwlist = 0;
11791166
p = kwlist;
11801167
for (;;) {
11811168
if (!*(p++)) break;
1182-
nkwds++;
1169+
nkwlist++;
11831170
}
11841171

1185-
if (nkwds != max) {
1172+
if (nkwlist != max) {
11861173
PyErr_SetString(PyExc_SystemError,
11871174
"number of items in format string and keyword list do not match");
11881175
return 0;
@@ -1192,7 +1179,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
11921179
string where it was left after processing args */
11931180

11941181
converted = 0;
1195-
for (i = nargs; i < nkwds; i++) {
1182+
for (i = nargs; i < nkwlist; i++) {
11961183
PyObject *item;
11971184
if (*format == '|')
11981185
format++;
@@ -1223,7 +1210,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
12231210
while (PyDict_Next(keywords, &pos, &key, &value)) {
12241211
match = 0;
12251212
ks = PyString_AsString(key);
1226-
for (i = 0; i < nkwds; i++) {
1213+
for (i = 0; i < nkwlist; i++) {
12271214
if (!strcmp(ks, kwlist[i])) {
12281215
match = 1;
12291216
break;

0 commit comments

Comments
 (0)