8000 WIP: bpo-1100942: Add datetime.time.strptime and datetime.date.strptime by matrixise · Pull Request #5578 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

WIP: bpo-1100942: Add datetime.time.strptime and datetime.date.strptime #5578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support tuple and list for the specs
  • Loading branch information
matrixise committed Mar 22, 2019
commit 9ac0af48a1cc7504d876c78939475360efba3d5d
9 changes: 7 additions & 2 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6360,13 +6360,18 @@ _check_invalid_datetime_specs(PyObject *module, PyObject *args)
return NULL;
}

assert(PyTuple_CheckExact(specs) || PyList_CheckExact(specs));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it be a list? This seems like unused code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first version was only for the tuples. After, I wanted to accept the list for my tests. but I am not against to only accept the tuples.


PyObject *found_invalid_specs = PyList_New(0);
if (found_invalid_specs == NULL) {
return NULL;
}

for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(specs); pos++) {
PyObject *spec = PyTuple_GET_ITEM(specs, pos);
PyObject *(*GetItem)(PyObject *, Py_ssize_t) = \
PyTuple_CheckExact(specs) ? PyTuple_GetItem : PyList_GetItem;

for (Py_ssize_t pos = 0; pos < PyObject_Size(specs); pos++) {
PyObject *spec = GetItem(specs, pos);
if (PySequence_Contains(format, spec)) {
PyList_Append(found_invalid_specs, spec);
}
Expand Down
0