@@ -156,25 +156,13 @@ ga_repr(PyObject *self)
156156 return NULL ;
157157}
158158
159- /* Checks if a variable number of names are from typing.py.
160- * If any one of the names are found, return 1, else 0.
161- **/
162- static inline int
163- is_typing_name (PyObject * obj , int num , ...)
159+ // isinstance(obj, TypeVar) without importing typing.py.
160+ // Returns -1 for errors.
161+ static int
162+ is_typevar (PyObject * obj )
164163{
165- va_list names ;
166- va_start (names , num );
167-
168164 PyTypeObject * type = Py_TYPE (obj );
169- int hit = 0 ;
170- for (int i = 0 ; i < num ; ++ i ) {
171- if (!strcmp (type -> tp_name , va_arg (names , const char * ))) {
172- hit = 1 ;
173- break ;
174- }
175- }
176- va_end (names );
177- if (!hit ) {
165+ if (strcmp (type -> tp_name , "TypeVar" ) != 0 ) {
178166 return 0 ;
179167 }
180168 PyObject * module = PyObject_GetAttrString ((PyObject * )type , "__module__" );
@@ -184,24 +172,9 @@ is_typing_name(PyObject *obj, int num, ...)
184172 int res = PyUnicode_Check (module )
185173 && _PyUnicode_EqualToASCIIString (module , "typing" );
186174 Py_DECREF (module );
187-
188175 return res ;
189176}
190177
191- // isinstance(obj, (TypeVar, ParamSpec)) without importing typing.py.
192- // Returns -1 for errors.
193- static inline int
194- is_typevarlike (PyObject * obj )
195- {
196- return is_typing_name (obj , 2 , "TypeVar" , "ParamSpec" );
197- }
198-
199- static inline int
200- is_paramspec (PyObject * obj )
201- {
202- return is_typing_name (obj , 1 , "ParamSpec" );
203- }
204-
205178// Index of item in self[:len], or -1 if not found (self is a tuple)
206179static Py_ssize_t
207180tuple_index (PyObject * self , Py_ssize_t len , PyObject * item )
@@ -236,7 +209,7 @@ make_parameters(PyObject *args)
236209 Py_ssize_t iparam = 0 ;
237210 for (Py_ssize_t iarg = 0 ; iarg < nargs ; iarg ++ ) {
238211 PyObject * t = PyTuple_GET_ITEM (args , iarg );
239- int typevar = is_typevarlike (t );
212+ int typevar = is_typevar (t );
240213 if (typevar < 0 ) {
241214 Py_DECREF (parameters );
242215 return NULL ;
@@ -306,14 +279,7 @@ subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems)
306279 if (iparam >= 0 ) {
307280 arg = argitems [iparam ];
308281 }
309- // convert all the lists inside args to tuples to help
310- // with caching in other libaries
311- if (PyList_CheckExact (arg )) {
312- arg = PyList_AsTuple (arg );
313- }
314- else {
315- Py_INCREF (arg );
316- }
282+ Py_INCREF (arg );
317283 PyTuple_SET_ITEM (subargs , i , arg );
318284 }
319285
@@ -348,19 +314,11 @@ ga_getitem(PyObject *self, PyObject *item)
348314 int is_tuple = PyTuple_Check (item );
349315 Py_ssize_t nitems = is_tuple ? PyTuple_GET_SIZE (item ) : 1 ;
350316 PyObject * * argitems = is_tuple ? & PyTuple_GET_ITEM (item , 0 ) : & item ;
351- // A special case in PEP 612 where if X = Callable[P, int],
352- // then X[int, str] == X[[int, str]].
353- if (nparams == 1 && nitems > 1 && is_tuple &&
354- is_paramspec (PyTuple_GET_ITEM (alias -> parameters , 0 ))) {
355- argitems = & item ;
356- }
357- else {
358- if (nitems != nparams ) {
359- return PyErr_Format (PyExc_TypeError ,
360- "Too %s arguments for %R" ,
361- nitems > nparams ? "many" : "few" ,
362- self );
363- }
317+ if (nitems != nparams ) {
318+ return PyErr_Format (PyExc_TypeError ,
319+ "Too %s arguments for %R" ,
320+ nitems > nparams ? "many" : "few" ,
321+ self );
364322 }
365323 /* Replace all type variables (specified by alias->parameters)
366324 with corresponding values specified by argitems.
@@ -375,7 +333,7 @@ ga_getitem(PyObject *self, PyObject *item)
375333 }
376334 for (Py_ssize_t iarg = 0 ; iarg < nargs ; iarg ++ ) {
377335 PyObject * arg = PyTuple_GET_ITEM (alias -> args , iarg );
378- int typevar = is_typevarlike (arg );
336+ int typevar = is_typevar (arg );
379337 if (typevar < 0 ) {
380338 Py_DECREF (newargs );
381339 return NULL ;
@@ -384,13 +342,7 @@ ga_getitem(PyObject *self, PyObject *item)
384342 Py_ssize_t iparam = tuple_index (alias -> parameters , nparams , arg );
385343 assert (iparam >= 0 );
386344 arg = argitems [iparam ];
387- // convert lists to tuples to help with caching in other libaries.
388- if (PyList_CheckExact (arg )) {
389- arg = PyList_AsTuple (arg );
390- }
391- else {
392- Py_INCREF (arg );
393- }
345+ Py_INCREF (arg );
394346 }
395347 else {
396348 arg = subs_tvars (arg , alias -> parameters , argitems );
0 commit comments