@@ -3139,41 +3139,45 @@ typedef struct {
31393139
31403140#define _zipobject_CAST (op ) ((zipobject *)(op))
31413141
3142+ /*[clinic input]
3143+ class zip "zipobject *" "&PyZip_Type"
3144+ @vectorcall
3145+ @classmethod
3146+ zip.__new__ as zip_new
3147+
3148+ *iterables: array
3149+ strict: bool = False
3150+
3151+ Iterate over several iterables in parallel, yielding tuples.
3152+
3153+ The zip object yields n-length tuples, where n is the number of
3154+ iterables passed as positional arguments to zip(). The i-th element
3155+ in every tuple comes from the i-th iterable argument to zip(). This
3156+ continues until the shortest argument is exhausted.
3157+
3158+ If strict is true and one of the arguments is exhausted before the
3159+ others, raise a ValueError.
3160+
3161+ >>> list(zip('abcdefg', range(3), range(4)))
3162+ [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]
3163+ [clinic start generated code]*/
3164+
31423165static PyObject *
3143- zip_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
3166+ zip_new_impl (PyTypeObject * type , PyObject * const * iterables ,
3167+ Py_ssize_t iterables_length , int strict )
3168+ /*[clinic end generated code: output=5e1a30829ce1f6ab input=4bd8e6a24e4bfb2e]*/
31443169{
31453170 zipobject * lz ;
31463171 Py_ssize_t i ;
31473172 PyObject * ittuple ; /* tuple of iterators */
31483173 PyObject * result ;
3149- Py_ssize_t tuplesize ;
3150- int strict = 0 ;
3151-
3152- if (kwds ) {
3153- PyObject * empty = PyTuple_New (0 );
3154- if (empty == NULL ) {
3155- return NULL ;
3156- }
3157- static char * kwlist [] = {"strict" , NULL };
3158- int parsed = PyArg_ParseTupleAndKeywords (
3159- empty , kwds , "|$p:zip" , kwlist , & strict );
3160- Py_DECREF (empty );
3161- if (!parsed ) {
3162- return NULL ;
3163- }
3164- }
3165-
3166- /* args must be a tuple */
3167- assert (PyTuple_Check (args ));
3168- tuplesize = PyTuple_GET_SIZE (args );
31693174
31703175 /* obtain iterators */
3171- ittuple = PyTuple_New (tuplesize );
3176+ ittuple = PyTuple_New (iterables_length );
31723177 if (ittuple == NULL )
31733178 return NULL ;
3174- for (i = 0 ; i < tuplesize ; ++ i ) {
3175- PyObject * item = PyTuple_GET_ITEM (args , i );
3176- PyObject * it = PyObject_GetIter (item );
3179+ for (i = 0 ; i < iterables_length ; ++ i ) {
3180+ PyObject * it = PyObject_GetIter (iterables [i ]);
31773181 if (it == NULL ) {
31783182 Py_DECREF (ittuple );
31793183 return NULL ;
@@ -3182,12 +3186,12 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
31823186 }
31833187
31843188 /* create a result holder */
3185- result = PyTuple_New (tuplesize );
3189+ result = PyTuple_New (iterables_length );
31863190 if (result == NULL ) {
31873191 Py_DECREF (ittuple );
31883192 return NULL ;
31893193 }
3190- for (i = 0 ; i < tuplesize ; i ++ ) {
3194+ for (i = 0 ; i < iterables_length ; i ++ ) {
31913195 PyTuple_SET_ITEM (result , i , Py_NewRef (Py_None ));
31923196 }
31933197
@@ -3199,7 +3203,7 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
31993203 return NULL ;
32003204 }
32013205 lz -> ittuple = ittuple ;
3202- lz -> tuplesize = tuplesize ;
3206+ lz -> tuplesize = iterables_length ;
32033207 lz -> result = result ;
32043208 lz -> strict = strict ;
32053209
@@ -3345,21 +3349,6 @@ static PyMethodDef zip_methods[] = {
33453349 {NULL } /* sentinel */
33463350};
33473351
3348- PyDoc_STRVAR (zip_doc ,
3349- "zip(*iterables, strict=False)\n\
3350- --\n\
3351- \n\
3352- The zip object yields n-length tuples, where n is the number of\n\
3353- iterables passed as positional arguments to zip(). The i-th element\n\
3354- in every tuple comes from the i-th iterable argument to zip(). This\n\
3355- continues until the shortest argument is exhausted.\n\
3356- \n\
3357- If strict is true and one of the arguments is exhausted before the\n\
3358- others, raise a ValueError.\n\
3359- \n\
3360- >>> list(zip('abcdefg', range(3), range(4)))\n\
3361- [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]" );
3362-
33633352PyTypeObject PyZip_Type = {
33643353 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
33653354 "zip" , /* tp_name */
@@ -3383,7 +3372,7 @@ PyTypeObject PyZip_Type = {
33833372 0 , /* tp_as_buffer */
33843373 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
33853374 Py_TPFLAGS_BASETYPE , /* tp_flags */
3386- zip_doc , /* tp_doc */
3375+ zip_new__doc__ , /* tp_doc */
33873376 zip_traverse , /* tp_traverse */
33883377 0 , /* tp_clear */
33893378 0 , /* tp_richcompare */
@@ -3402,6 +3391,7 @@ PyTypeObject PyZip_Type = {
34023391 PyType_GenericAlloc , /* tp_alloc */
34033392 zip_new , /* tp_new */
34043393 PyObject_GC_Del , /* tp_free */
3394+ .tp_vectorcall = zip_vectorcall ,
34053395};
34063396
34073397
0 commit comments