@@ -840,33 +840,31 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
840840    return  result ;
841841}
842842
843- /*[clinic input] 
844- dir as builtin_dir 
845- 
846-     arg: object = NULL 
847-     / 
848- 
849- Show attributes of an object. 
850- 
851- If called without an argument, return the names in the current scope. 
852- Else, return an alphabetized list of names comprising (some of) the attributes 
853- of the given object, and of attributes reachable from it. 
854- If the object supplies a method named __dir__, it will be used; otherwise 
855- the default dir() logic is used and returns: 
856-   for a module object: the module's attributes. 
857-   for a class object:  its attributes, and recursively the attributes 
858-     of its bases. 
859-   for any other object: its attributes, its class's attributes, and 
860-     recursively the attributes of its class's base classes. 
861- [clinic start generated code]*/ 
862- 
843+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ 
863844static  PyObject  * 
864- builtin_dir_impl (PyObject  * module , PyObject  * arg )
865- /*[clinic end generated code: output=24f2c7a52c1e3b08 input=ed6d6ccb13d52251]*/ 
845+ builtin_dir (PyObject  * self , PyObject  * args )
866846{
847+     PyObject  * arg  =  NULL ;
848+ 
849+     if  (!PyArg_UnpackTuple (args , "dir" , 0 , 1 , & arg ))
850+         return  NULL ;
867851    return  PyObject_Dir (arg );
868852}
869853
854+ PyDoc_STRVAR (dir_doc ,
855+ "dir([object]) -> list of strings\n" 
856+ "\n" 
857+ "If called without an argument, return the names in the current scope.\n" 
858+ "Else, return an alphabetized list of names comprising (some of) the attributes\n" 
859+ "of the given object, and of attributes reachable from it.\n" 
860+ "If the object supplies a method named __dir__, it will be used; otherwise\n" 
861+ "the default dir() logic is used and returns:\n" 
862+ "  for a module object: the module's attributes.\n" 
863+ "  for a class object:  its attributes, and recursively the attributes\n" 
864+ "    of its bases.\n" 
865+ "  for any other object: its attributes, its class's attributes, and\n" 
866+ "    recursively the attributes of its class's base classes." );
867+ 
870868/*[clinic input] 
871869divmod as builtin_divmod 
872870
@@ -1136,39 +1134,36 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
11361134}
11371135
11381136
1139- /*[clinic input] 
1140- getattr as builtin_getattr 
1141- 
1142-     object: object 
1143-     name: object 
1144-     default: object = NULL 
1145-     / 
1146- 
1147- Get a named attribute from an object. 
1148- 
1149- getattr(x, 'y') is equivalent to x.y 
1150- When a default argument is given, it is returned when the attribute doesn't 
1151- exist; without it, an exception is raised in that case. 
1152- [clinic start generated code]*/ 
1153- 
1137+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ 
11541138static  PyObject  * 
1155- builtin_getattr_impl (PyObject  * module , PyObject  * object , PyObject  * name ,
1156-                      PyObject  * default_value )
1157- /*[clinic end generated code: output=74ad0e225e3f701c input=d7562cd4c3556171]*/ 
1139+ builtin_getattr (PyObject  * self , PyObject  * const  * args , Py_ssize_t  nargs )
11581140{
1159-     PyObject  * result ;
1141+     PyObject  * v , * name , * result ;
1142+ 
1143+     if  (!_PyArg_CheckPositional ("getattr" , nargs , 2 , 3 ))
1144+         return  NULL ;
11601145
1161-     if  (default_value  !=  NULL ) {
1162-         if  (_PyObject_LookupAttr (object , name , & result ) ==  0 ) {
1163-             return  Py_NewRef (default_value );
1146+     v  =  args [0 ];
1147+     name  =  args [1 ];
1148+     if  (nargs  >  2 ) {
1149+         if  (_PyObject_LookupAttr (v , name , & result ) ==  0 ) {
1150+             PyObject  * dflt  =  args [2 ];
1151+             return  Py_NewRef (dflt );
11641152        }
11651153    }
11661154    else  {
1167-         result  =  PyObject_GetAttr (object , name );
1155+         result  =  PyObject_GetAttr (v , name );
11681156    }
11691157    return  result ;
11701158}
11711159
1160+ PyDoc_STRVAR (getattr_doc ,
1161+ "getattr(object, name[, default]) -> value\n\ 
1162+ \n\ 
1163+ Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\ 
1164+ When a default argument is given, it is returned when the attribute doesn't\n\ 
1165+ exist; without it, an exception is raised in that case." );
1166+ 
11721167
11731168/*[clinic input] 
11741169globals as builtin_globals 
@@ -1480,43 +1475,34 @@ PyTypeObject PyMap_Type = {
14801475};
14811476
14821477
1483- /*[clinic input] 
1484- next as builtin_next 
1485- 
1486-     iterator: object 
1487-     default: object = NULL 
1488-     / 
1489- 
1490- Return the next item from the iterator. 
1491- 
1492- If default is given and the iterator is exhausted, 
1493- it is returned instead of raising StopIteration. 
1494- [clinic start generated code]*/ 
1495- 
1478+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ 
14961479static  PyObject  * 
1497- builtin_next_impl (PyObject  * module , PyObject  * iterator ,
1498-                   PyObject  * default_value )
1499- /*[clinic end generated code: output=a38a94eeb447fef9 input=180f9984f182020f]*/ 
1480+ builtin_next (PyObject  * self , PyObject  * const  * args , Py_ssize_t  nargs )
15001481{
1501-     PyObject  * res ;
1482+     PyObject  * it , * res ;
1483+ 
1484+     if  (!_PyArg_CheckPositional ("next" , nargs , 1 , 2 ))
1485+         return  NULL ;
15021486
1503-     if  (!PyIter_Check (iterator )) {
1487+     it  =  args [0 ];
1488+     if  (!PyIter_Check (it )) {
15041489        PyErr_Format (PyExc_TypeError ,
15051490            "'%.200s' object is not an iterator" ,
1506-             Py_TYPE (iterator )-> tp_name );
1491+             Py_TYPE (it )-> tp_name );
15071492        return  NULL ;
15081493    }
15091494
1510-     res  =  (* Py_TYPE (iterator )-> tp_iternext )(iterator );
1495+     res  =  (* Py_TYPE (it )-> tp_iternext )(it );
15111496    if  (res  !=  NULL ) {
15121497        return  res ;
1513-     } else  if  (default_value  !=  NULL ) {
1498+     } else  if  (nargs  >  1 ) {
1499+         PyObject  * def  =  args [1 ];
15141500        if  (PyErr_Occurred ()) {
15151501            if (!PyErr_ExceptionMatches (PyExc_StopIteration ))
15161502                return  NULL ;
15171503            PyErr_Clear ();
15181504        }
1519-         return  Py_NewRef (default_value );
1505+         return  Py_NewRef (def );
15201506    } else  if  (PyErr_Occurred ()) {
15211507        return  NULL ;
15221508    } else  {
@@ -1525,6 +1511,12 @@ builtin_next_impl(PyObject *module, PyObject *iterator,
15251511    }
15261512}
15271513
1514+ PyDoc_STRVAR (next_doc ,
1515+ "next(iterator[, default])\n\ 
1516+ \n\ 
1517+ Return the next item from the iterator. If default is given and the iterator\n\ 
1518+ is exhausted, it is returned instead of raising StopIteration." );
1519+ 
15281520
15291521/*[clinic input] 
15301522setattr as builtin_setattr 
@@ -1617,33 +1609,34 @@ builtin_hex(PyObject *module, PyObject *number)
16171609}
16181610
16191611
1620- /*[clinic input] 
1621- iter as builtin_iter 
1622- 
1623-     object: object 
1624-     sentinel: object = NULL 
1625-     / 
1626- 
1627- Get an iterator from an object. 
1628- 
1629- In the first form, the argument must supply its own iterator, or be a sequence. 
1630- In the second form, the callable is called until it returns the sentinel. 
1631- [clinic start generated code]*/ 
1632- 
1612+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ 
16331613static  PyObject  * 
1634- builtin_iter_impl (PyObject  * module , PyObject  * object , PyObject  * sentinel )
1635- /*[clinic end generated code: output=12cf64203c195a94 input=a5d64d9d81880ba6]*/ 
1614+ builtin_iter (PyObject  * self , PyObject  * const  * args , Py_ssize_t  nargs )
16361615{
1637-     if  (sentinel  ==  NULL )
1638-         return  PyObject_GetIter (object );
1639-     if  (!PyCallable_Check (object )) {
1616+     PyObject  * v ;
1617+ 
1618+     if  (!_PyArg_CheckPositional ("iter" , nargs , 1 , 2 ))
1619+         return  NULL ;
1620+     v  =  args [0 ];
1621+     if  (nargs  ==  1 )
1622+         return  PyObject_GetIter (v );
1623+     if  (!PyCallable_Check (v )) {
16401624        PyErr_SetString (PyExc_TypeError ,
1641-                         "iter(object, sentinel ): object  must be callable" );
1625+                         "iter(v, w ): v  must be callable" );
16421626        return  NULL ;
16431627    }
1644-     return  PyCallIter_New (object , sentinel );
1628+     PyObject  * sentinel  =  args [1 ];
1629+     return  PyCallIter_New (v , sentinel );
16451630}
16461631
1632+ PyDoc_STRVAR (iter_doc ,
1633+ "iter(iterable) -> iterator\n\ 
1634+ iter(callable, sentinel) -> iterator\n\ 
1635+ \n\ 
1636+ Get an iterator from an object.  In the first form, the argument must\n\ 
1637+ supply its own iterator, or be a sequence.\n\ 
1638+ In the second form, the callable is called until it returns the sentinel." );
1639+ 
16471640
16481641/*[clinic input] 
16491642aiter as builtin_aiter 
@@ -2443,36 +2436,33 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
24432436}
24442437
24452438
2446- /*[clinic input] 
2447- vars as builtin_vars 
2448- 
2449-     object: object = NULL 
2450-     / 
2451- 
2452- Show vars. 
2453- 
2454- Without arguments, equivalent to locals(). 
2455- With an argument, equivalent to object.__dict__. 
2456- [clinic start generated code]*/ 
2457- 
2439+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ 
24582440static  PyObject  * 
2459- builtin_vars_impl (PyObject  * module , PyObject  * object )
2460- /*[clinic end generated code: output=840a7f64007a3e0a input=80cbdef9182c4ba3]*/ 
2441+ builtin_vars (PyObject  * self , PyObject  * args )
24612442{
2443+     PyObject  * v  =  NULL ;
24622444    PyObject  * d ;
24632445
2464-     if  (object  ==  NULL ) {
2446+     if  (!PyArg_UnpackTuple (args , "vars" , 0 , 1 , & v ))
2447+         return  NULL ;
2448+     if  (v  ==  NULL ) {
24652449        d  =  _PyEval_GetFrameLocals ();
24662450    }
24672451    else  {
2468-         if  (_PyObject_LookupAttr (object , & _Py_ID (__dict__ ), & d ) ==  0 ) {
2452+         if  (_PyObject_LookupAttr (v , & _Py_ID (__dict__ ), & d ) ==  0 ) {
24692453            PyErr_SetString (PyExc_TypeError ,
24702454                "vars() argument must have __dict__ attribute" );
24712455        }
24722456    }
24732457    return  d ;
24742458}
24752459
2460+ PyDoc_STRVAR (vars_doc ,
2461+ "vars([object]) -> dictionary\n\ 
2462+ \n\ 
2463+ Without arguments, equivalent to locals().\n\ 
2464+ With an argument, equivalent to object.__dict__." );
2465+ 
24762466
24772467/*[clinic input] 
24782468sum as builtin_sum 
@@ -3024,12 +3014,12 @@ static PyMethodDef builtin_methods[] = {
30243014    BUILTIN_CHR_METHODDEF 
30253015    BUILTIN_COMPILE_METHODDEF 
30263016    BUILTIN_DELATTR_METHODDEF 
3027-     BUILTIN_DIR_METHODDEF 
3017+     { "dir" ,  builtin_dir ,  METH_VARARGS ,  dir_doc }, 
30283018    BUILTIN_DIVMOD_METHODDEF 
30293019    BUILTIN_EVAL_METHODDEF 
30303020    BUILTIN_EXEC_METHODDEF 
30313021    BUILTIN_FORMAT_METHODDEF 
3032-     BUILTIN_GETATTR_METHODDEF 
3022+     { "getattr" ,  _PyCFunction_CAST ( builtin_getattr ),  METH_FASTCALL ,  getattr_doc }, 
30333023    BUILTIN_GLOBALS_METHODDEF 
30343024    BUILTIN_HASATTR_METHODDEF 
30353025    BUILTIN_HASH_METHODDEF 
@@ -3038,13 +3028,13 @@ static PyMethodDef builtin_methods[] = {
30383028    BUILTIN_INPUT_METHODDEF 
30393029    BUILTIN_ISINSTANCE_METHODDEF 
30403030    BUILTIN_ISSUBCLASS_METHODDEF 
3041-     BUILTIN_ITER_METHODDEF 
3031+     { "iter" ,  _PyCFunction_CAST ( builtin_iter ),  METH_FASTCALL ,  iter_doc }, 
30423032    BUILTIN_AITER_METHODDEF 
30433033    BUILTIN_LEN_METHODDEF 
30443034    BUILTIN_LOCALS_METHODDEF 
30453035    {"max" , _PyCFunction_CAST (builtin_max ), METH_VARARGS  | METH_KEYWORDS , max_doc },
30463036    {"min" , _PyCFunction_CAST (builtin_min ), METH_VARARGS  | METH_KEYWORDS , min_doc },
3047-     BUILTIN_NEXT_METHODDEF 
3037+     { "next" ,  _PyCFunction_CAST ( builtin_next ),  METH_FASTCALL ,  next_doc }, 
30483038    BUILTIN_ANEXT_METHODDEF 
30493039    BUILTIN_OCT_METHODDEF 
30503040    BUILTIN_ORD_METHODDEF 
@@ -3055,7 +3045,7 @@ static PyMethodDef builtin_methods[] = {
30553045    BUILTIN_SETATTR_METHODDEF 
30563046    BUILTIN_SORTED_METHODDEF 
30573047    BUILTIN_SUM_METHODDEF 
3058-     BUILTIN_VARS_METHODDEF 
3048+     { "vars" ,             builtin_vars ,        METH_VARARGS ,  vars_doc }, 
30593049    {NULL ,              NULL },
30603050};
30613051
0 commit comments