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

Skip to content

Commit 9ac0af4

Browse files
committed
Support tuple and list for the specs
1 parent a048f0e commit 9ac0af4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Modules/_datetimemodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6360,13 +6360,18 @@ _check_invalid_datetime_specs(PyObject *module, PyObject *args)
63606360
return NULL;
63616361
}
63626362

6363+
assert(PyTuple_CheckExact(specs) || PyList_CheckExact(specs));
6364+
63636365
PyObject *found_invalid_specs = PyList_New(0);
63646366
if (found_invalid_specs == NULL) {
63656367
return NULL;
63666368
}
63676369

6368-
for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(specs); pos++) {
6369-
PyObject *spec = PyTuple_GET_ITEM(specs, pos);
6370+
PyObject *(*GetItem)(PyObject *, Py_ssize_t) = \
6371+
PyTuple_CheckExact(specs) ? PyTuple_GetItem : PyList_GetItem;
6372+
6373+
for (Py_ssize_t pos = 0; pos < PyObject_Size(specs); pos++) {
6374+
PyObject *spec = GetItem(specs, pos);
63706375
if (PySequence_Contains(format, spec)) {
63716376
PyList_Append(found_invalid_specs, spec);
63726377
}

0 commit comments

Comments
 (0)