@@ -28,6 +28,7 @@ typedef struct {
2828#define _enumobject_CAST (op ) ((enumobject *)(op))
2929
3030/*[clinic input]
31+ @vectorcall
3132@classmethod
3233enumerate.__new__ as enum_new
3334
@@ -46,7 +47,7 @@ enumerate is useful for obtaining an indexed list:
4647
4748static PyObject *
4849enum_new_impl (PyTypeObject * type , PyObject * iterable , PyObject * start )
49- /*[clinic end generated code: output=e95e6e439f812c10 input=782e4911efcb8acf ]*/
50+ /*[clinic end generated code: output=e95e6e439f812c10 input=a139e88889360e8f ]*/
5051{
5152 enumobject * en ;
5253
@@ -87,71 +88,6 @@ enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start)
8788 return (PyObject * )en ;
8889}
8990
90- static int check_keyword (PyObject * kwnames , int index ,
91- const char * name )
92- {
93- PyObject * kw = PyTuple_GET_ITEM (kwnames , index );
94- if (!_PyUnicode_EqualToASCIIString (kw , name )) {
95- PyErr_Format (PyExc_TypeError ,
96- "'%S' is an invalid keyword argument for enumerate()" , kw );
97- return 0 ;
98- }
99- return 1 ;
100- }
101-
102- // TODO: Use AC when bpo-43447 is supported
103- static PyObject *
104- enumerate_vectorcall (PyObject * type , PyObject * const * args ,
105- size_t nargsf , PyObject * kwnames )
106- {
107- PyTypeObject * tp = _PyType_CAST (type );
108- Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
109- Py_ssize_t nkwargs = 0 ;
110- if (kwnames != NULL ) {
111- nkwargs = PyTuple_GET_SIZE (kwnames );
112- }
113-
114- // Manually implement enumerate(iterable, start=...)
115- if (nargs + nkwargs == 2 ) {
116- if (nkwargs == 1 ) {
117- if (!check_keyword (kwnames , 0 , "start" )) {
118- return NULL ;
119- }
120- } else if (nkwargs == 2 ) {
121- PyObject * kw0 = PyTuple_GET_ITEM (kwnames , 0 );
122- if (_PyUnicode_EqualToASCIIString (kw0 , "start" )) {
123- if (!check_keyword (kwnames , 1 , "iterable" )) {
124- return NULL ;
125- }
126- return enum_new_impl (tp , args [1 ], args [0 ]);
127- }
128- if (!check_keyword (kwnames , 0 , "iterable" ) ||
129- !check_keyword (kwnames , 1 , "start" )) {
130- return NULL ;
131- }
132-
133- }
134- return enum_new_impl (tp , args [0 ], args [1 ]);
135- }
136-
137- if (nargs + nkwargs == 1 ) {
138- if (nkwargs == 1 && !check_keyword (kwnames , 0 , "iterable" )) {
139- return NULL ;
140- }
141- return enum_new_impl (tp , args [0 ], NULL );
142- }
143-
144- if (nargs == 0 ) {
145- PyErr_SetString (PyExc_TypeError ,
146- "enumerate() missing required argument 'iterable'" );
147- return NULL ;
148- }
149-
150- PyErr_Format (PyExc_TypeError ,
151- "enumerate() takes at most 2 arguments (%d given)" , nargs + nkwargs );
152- return NULL ;
153- }
154-
15591static void
15692enum_dealloc (PyObject * op )
15793{
@@ -350,7 +286,7 @@ PyTypeObject PyEnum_Type = {
350286 PyType_GenericAlloc , /* tp_alloc */
351287 enum_new , /* tp_new */
352288 PyObject_GC_Del , /* tp_free */
353- .tp_vectorcall = enumerate_vectorcall
289+ .tp_vectorcall = enum_vectorcall
354290};
355291
356292/* Reversed Object ***************************************************************/
@@ -364,6 +300,7 @@ typedef struct {
364300#define _reversedobject_CAST (op ) ((reversedobject *)(op))
365301
366302/*[clinic input]
303+ @vectorcall
367304@classmethod
368305reversed.__new__ as reversed_new
369306
@@ -375,7 +312,7 @@ Return a reverse iterator over the values of the given sequence.
375312
376313static PyObject *
377314reversed_new_impl (PyTypeObject * type , PyObject * seq )
378- /*[clinic end generated code: output=f7854cc1df26f570 input=4781869729e3ba50 ]*/
315+ /*[clinic end generated code: output=f7854cc1df26f570 input=7db568182ab28c59 ]*/
379316{
380317 Py_ssize_t n ;
381318 PyObject * reversed_meth ;
@@ -417,22 +354,6 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq)
417354 return (PyObject * )ro ;
418355}
419356
420- static PyObject *
421- reversed_vectorcall (PyObject * type , PyObject * const * args ,
422- size_t nargsf , PyObject * kwnames )
423- {
424- if (!_PyArg_NoKwnames ("reversed" , kwnames )) {
425- return NULL ;
426- }
427-
428- Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
429- if (!_PyArg_CheckPositional ("reversed" , nargs , 1 , 1 )) {
430- return NULL ;
431- }
432-
433- return reversed_new_impl (_PyType_CAST (type ), args [0 ]);
434- }
435-
436357static void
437358reversed_dealloc (PyObject * op )
438359{
0 commit comments