Skip to content

Commit 8fcec2d

Browse files
eendebakptclaude
andcommitted
Use the documented signature in the clinic input of map()
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 8ef1388 commit 8fcec2d

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

‎Python/bltinmodule.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,33 +1432,37 @@ class map "mapobject *" "&PyMap_Type"
14321432
@classmethod
14331433
map.__new__ as map_new
14341434
1435-
*args: array
1435+
function: object
1436+
iterable: object
1437+
/
1438+
*iterables: array
14361439
strict: bool = False
14371440
[clinic start generated code]*/
14381441

14391442
static PyObject *
1440-
map_new_impl(PyTypeObject *type, PyObject * const *args,
1441-
Py_ssize_t args_length, int strict)
1442-
/*[clinic end generated code: output=a42e882981848ca5 input=f037decab456747b]*/
1443+
map_new_impl(PyTypeObject *type, PyObject *function, PyObject *iterable,
1444+
PyObject * const *iterables, Py_ssize_t iterables_length,
1445+
int strict)
1446+
/*[clinic end generated code: output=de1354b02d08604b input=5fbe90bd74aaa2e2]*/
14431447
{
1444-
if (args_length < 2) {
1445-
PyErr_SetString(PyExc_TypeError,
1446-
"map() must have at least two arguments.");
1448+
PyObject *iters = PyTuple_New(iterables_length + 1);
1449+
if (iters == NULL) {
14471450
return NULL;
14481451
}
14491452

1450-
PyObject *iters = PyTuple_New(args_length - 1);
1451-
if (iters == NULL) {
1453+
PyObject *it = PyObject_GetIter(iterable);
1454+
if (it == NULL) {
1455+
Py_DECREF(iters);
14521456
return NULL;
14531457
}
1454-
1455-
for (Py_ssize_t i = 1; i < args_length; i++) {
1456-
PyObject *it = PyObject_GetIter(args[i]);
1458+
PyTuple_SET_ITEM(iters, 0, it);
1459+
for (Py_ssize_t i = 0; i < iterables_length; i++) {
1460+
it = PyObject_GetIter(iterables[i]);
14571461
if (it == NULL) {
14581462
Py_DECREF(iters);
14591463
return NULL;
14601464
}
1461-
PyTuple_SET_ITEM(iters, i - 1, it);
1465+
PyTuple_SET_ITEM(iters, i + 1, it);
14621466
}
14631467

14641468
mapobject *lz = (mapobject *)type->tp_alloc(type, 0);
@@ -1467,7 +1471,7 @@ map_new_impl(PyTypeObject *type, PyObject * const *args,
14671471
return NULL;
14681472
}
14691473
lz->iters = iters;
1470-
lz->func = Py_NewRef(args[0]);
1474+
lz->func = Py_NewRef(function);
14711475
lz->strict = strict;
14721476

14731477
return (PyObject *)lz;

‎Python/clinic/bltinmodule.c.h‎

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)