summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2021-03-16 04:02:25 (GMT)
committerGitHub <noreply@github.com>2021-03-16 04:02:25 (GMT)
commit448801da96c70699e2ca0798efdfe86d45f37f06 (patch)
treebabbdb97bfc46fffe4cb0f938c95154b53b22665 /Modules
parentd69ae758a0606c142c305123dcbad3e3e42d664f (diff)
downloadcpython-448801da96c70699e2ca0798efdfe86d45f37f06.zip
cpython-448801da96c70699e2ca0798efdfe86d45f37f06.tar.gz
cpython-448801da96c70699e2ca0798efdfe86d45f37f06.tar.bz2
bpo-41361: Optimized argument parsing for deque_rotate (GH-24796)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_collectionsmodule.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 90bafb0..ca63f71 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -880,9 +880,20 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
{
Py_ssize_t n=1;
- if (!_PyArg_ParseStack(args, nargs, "|n:rotate", &n)) {
+ if (!_PyArg_CheckPositional("deque.rotate", nargs, 0, 1)) {
return NULL;
}
+ if (nargs) {
+ PyObject *index = _PyNumber_Index(args[0]);
+ if (index == NULL) {
+ return NULL;
+ }
+ n = PyLong_AsSsize_t(index);
+ Py_DECREF(index);
+ if (n == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ }
if (!_deque_rotate(deque, n))
Py_RETURN_NONE;