@@ -842,33 +842,31 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
842842 return result ;
843843}
844844
845- /*[clinic input]
846- dir as builtin_dir
847-
848- arg: object = NULL
849- /
850-
851- Show attributes of an object.
852-
853- If called without an argument, return the names in the current scope.
854- Else, return an alphabetized list of names comprising (some of) the attributes
855- of the given object, and of attributes reachable from it.
856- If the object supplies a method named __dir__, it will be used; otherwise
857- the default dir() logic is used and returns:
858- for a module object: the module's attributes.
859- for a class object: its attributes, and recursively the attributes
860- of its bases.
861- for any other object: its attributes, its class's attributes, and
862- recursively the attributes of its class's base classes.
863- [clinic start generated code]*/
864-
845+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
865846static PyObject *
866- builtin_dir_impl (PyObject * module , PyObject * arg )
867- /*[clinic end generated code: output=24f2c7a52c1e3b08 input=ed6d6ccb13d52251]*/
847+ builtin_dir (PyObject * self , PyObject * args )
868848{
849+ PyObject * arg = NULL ;
850+
851+ if (!PyArg_UnpackTuple (args , "dir" , 0 , 1 , & arg ))
852+ return NULL ;
869853 return PyObject_Dir (arg );
870854}
871855
856+ PyDoc_STRVAR (dir_doc ,
857+ "dir([object]) -> list of strings\n"
858+ "\n"
859+ "If called without an argument, return the names in the current scope.\n"
860+ "Else, return an alphabetized list of names comprising (some of) the attributes\n"
861+ "of the given object, and of attributes reachable from it.\n"
862+ "If the object supplies a method named __dir__, it will be used; otherwise\n"
863+ "the default dir() logic is used and returns:\n"
864+ " for a module object: the module's attributes.\n"
865+ " for a class object: its attributes, and recursively the attributes\n"
866+ " of its bases.\n"
867+ " for any other object: its attributes, its class's attributes, and\n"
868+ " recursively the attributes of its class's base classes." );
869+
872870/*[clinic input]
873871divmod as builtin_divmod
874872
@@ -1138,39 +1136,36 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
11381136}
11391137
11401138
1141- /*[clinic input]
1142- getattr as builtin_getattr
1143-
1144- object: object
1145- name: object
1146- default: object = NULL
1147- /
1148-
1149- Get a named attribute from an object.
1150-
1151- getattr(x, 'y') is equivalent to x.y
1152- When a default argument is given, it is returned when the attribute doesn't
1153- exist; without it, an exception is raised in that case.
1154- [clinic start generated code]*/
1155-
1139+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
11561140static PyObject *
1157- builtin_getattr_impl (PyObject * module , PyObject * object , PyObject * name ,
1158- PyObject * default_value )
1159- /*[clinic end generated code: output=74ad0e225e3f701c input=d7562cd4c3556171]*/
1141+ builtin_getattr (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
11601142{
1161- PyObject * result ;
1143+ PyObject * v , * name , * result ;
1144+
1145+ if (!_PyArg_CheckPositional ("getattr" , nargs , 2 , 3 ))
1146+ return NULL ;
11621147
1163- if (default_value != NULL ) {
1164- if (PyObject_GetOptionalAttr (object , name , & result ) == 0 ) {
1165- return Py_NewRef (default_value );
1148+ v = args [0 ];
1149+ name = args [1 ];
1150+ if (nargs > 2 ) {
1151+ if (PyObject_GetOptionalAttr (v , name , & result ) == 0 ) {
1152+ PyObject * dflt = args [2 ];
1153+ return Py_NewRef (dflt );
11661154 }
11671155 }
11681156 else {
1169- result = PyObject_GetAttr (object , name );
1157+ result = PyObject_GetAttr (v , name );
11701158 }
11711159 return result ;
11721160}
11731161
1162+ PyDoc_STRVAR (getattr_doc ,
1163+ "getattr(object, name[, default]) -> value\n\
1164+ \n\
1165+ Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\
1166+ When a default argument is given, it is returned when the attribute doesn't\n\
1167+ exist; without it, an exception is raised in that case." );
1168+
11741169
11751170/*[clinic input]
11761171globals as builtin_globals
@@ -1482,43 +1477,34 @@ PyTypeObject PyMap_Type = {
14821477};
14831478
14841479
1485- /*[clinic input]
1486- next as builtin_next
1487-
1488- iterator: object
1489- default: object = NULL
1490- /
1491-
1492- Return the next item from the iterator.
1493-
1494- If default is given and the iterator is exhausted,
1495- it is returned instead of raising StopIteration.
1496- [clinic start generated code]*/
1497-
1480+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
14981481static PyObject *
1499- builtin_next_impl (PyObject * module , PyObject * iterator ,
1500- PyObject * default_value )
1501- /*[clinic end generated code: output=a38a94eeb447fef9 input=180f9984f182020f]*/
1482+ builtin_next (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
15021483{
1503- PyObject * res ;
1484+ PyObject * it , * res ;
1485+
1486+ if (!_PyArg_CheckPositional ("next" , nargs , 1 , 2 ))
1487+ return NULL ;
15041488
1505- if (!PyIter_Check (iterator )) {
1489+ it = args [0 ];
1490+ if (!PyIter_Check (it )) {
15061491 PyErr_Format (PyExc_TypeError ,
15071492 "'%.200s' object is not an iterator" ,
1508- Py_TYPE (iterator )-> tp_name );
1493+ Py_TYPE (it )-> tp_name );
15091494 return NULL ;
15101495 }
15111496
1512- res = (* Py_TYPE (iterator )-> tp_iternext )(iterator );
1497+ res = (* Py_TYPE (it )-> tp_iternext )(it );
15131498 if (res != NULL ) {
15141499 return res ;
1515- } else if (default_value != NULL ) {
1500+ } else if (nargs > 1 ) {
1501+ PyObject * def = args [1 ];
15161502 if (PyErr_Occurred ()) {
15171503 if (!PyErr_ExceptionMatches (PyExc_StopIteration ))
15181504 return NULL ;
15191505 PyErr_Clear ();
15201506 }
1521- return Py_NewRef (default_value );
1507+ return Py_NewRef (def );
15221508 } else if (PyErr_Occurred ()) {
15231509 return NULL ;
15241510 } else {
@@ -1527,6 +1513,12 @@ builtin_next_impl(PyObject *module, PyObject *iterator,
15271513 }
15281514}
15291515
1516+ PyDoc_STRVAR (next_doc ,
1517+ "next(iterator[, default])\n\
1518+ \n\
1519+ Return the next item from the iterator. If default is given and the iterator\n\
1520+ is exhausted, it is returned instead of raising StopIteration." );
1521+
15301522
15311523/*[clinic input]
15321524setattr as builtin_setattr
@@ -1620,33 +1612,34 @@ builtin_hex(PyObject *module, PyObject *number)
16201612}
16211613
16221614
1623- /*[clinic input]
1624- iter as builtin_iter
1625-
1626- object: object
1627- sentinel: object = NULL
1628- /
1629-
1630- Get an iterator from an object.
1631-
1632- In the first form, the argument must supply its own iterator, or be a sequence.
1633- In the second form, the callable is called until it returns the sentinel.
1634- [clinic start generated code]*/
1635-
1615+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
16361616static PyObject *
1637- builtin_iter_impl (PyObject * module , PyObject * object , PyObject * sentinel )
1638- /*[clinic end generated code: output=12cf64203c195a94 input=a5d64d9d81880ba6]*/
1617+ builtin_iter (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
16391618{
1640- if (sentinel == NULL )
1641- return PyObject_GetIter (object );
1642- if (!PyCallable_Check (object )) {
1619+ PyObject * v ;
1620+
1621+ if (!_PyArg_CheckPositional ("iter" , nargs , 1 , 2 ))
1622+ return NULL ;
1623+ v = args [0 ];
1624+ if (nargs == 1 )
1625+ return PyObject_GetIter (v );
1626+ if (!PyCallable_Check (v )) {
16431627 PyErr_SetString (PyExc_TypeError ,
1644- "iter(object, sentinel ): object must be callable" );
1628+ "iter(v, w ): v must be callable" );
16451629 return NULL ;
16461630 }
1647- return PyCallIter_New (object , sentinel );
1631+ PyObject * sentinel = args [1 ];
1632+ return PyCallIter_New (v , sentinel );
16481633}
16491634
1635+ PyDoc_STRVAR (iter_doc ,
1636+ "iter(iterable) -> iterator\n\
1637+ iter(callable, sentinel) -> iterator\n\
1638+ \n\
1639+ Get an iterator from an object. In the first form, the argument must\n\
1640+ supply its own iterator, or be a sequence.\n\
1641+ In the second form, the callable is called until it returns the sentinel." );
1642+
16501643
16511644/*[clinic input]
16521645aiter as builtin_aiter
@@ -2444,36 +2437,33 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
24442437}
24452438
24462439
2447- /*[clinic input]
2448- vars as builtin_vars
2449-
2450- object: object = NULL
2451- /
2452-
2453- Show vars.
2454-
2455- Without arguments, equivalent to locals().
2456- With an argument, equivalent to object.__dict__.
2457- [clinic start generated code]*/
2458-
2440+ /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
24592441static PyObject *
2460- builtin_vars_impl (PyObject * module , PyObject * object )
2461- /*[clinic end generated code: output=840a7f64007a3e0a input=80cbdef9182c4ba3]*/
2442+ builtin_vars (PyObject * self , PyObject * args )
24622443{
2444+ PyObject * v = NULL ;
24632445 PyObject * d ;
24642446
2465- if (object == NULL ) {
2466- d = _PyEval_GetFrameLocals ();
2447+ if (!PyArg_UnpackTuple (args , "vars" , 0 , 1 , & v ))
2448+ return NULL ;
2449+ if (v == NULL ) {
2450+ d = Py_XNewRef (PyEval_GetLocals ());
24672451 }
24682452 else {
2469- if (PyObject_GetOptionalAttr (object , & _Py_ID (__dict__ ), & d ) == 0 ) {
2453+ if (PyObject_GetOptionalAttr (v , & _Py_ID (__dict__ ), & d ) == 0 ) {
24702454 PyErr_SetString (PyExc_TypeError ,
24712455 "vars() argument must have __dict__ attribute" );
24722456 }
24732457 }
24742458 return d ;
24752459}
24762460
2461+ PyDoc_STRVAR (vars_doc ,
2462+ "vars([object]) -> dictionary\n\
2463+ \n\
2464+ Without arguments, equivalent to locals().\n\
2465+ With an argument, equivalent to object.__dict__." );
2466+
24772467
24782468/*[clinic input]
24792469sum as builtin_sum
@@ -3022,12 +3012,12 @@ static PyMethodDef builtin_methods[] = {
30223012 BUILTIN_CHR_METHODDEF
30233013 BUILTIN_COMPILE_METHODDEF
30243014 BUILTIN_DELATTR_METHODDEF
3025- BUILTIN_DIR_METHODDEF
3015+ { "dir" , builtin_dir , METH_VARARGS , dir_doc },
30263016 BUILTIN_DIVMOD_METHODDEF
30273017 BUILTIN_EVAL_METHODDEF
30283018 BUILTIN_EXEC_METHODDEF
30293019 BUILTIN_FORMAT_METHODDEF
3030- BUILTIN_GETATTR_METHODDEF
3020+ { "getattr" , _PyCFunction_CAST ( builtin_getattr ), METH_FASTCALL , getattr_doc },
30313021 BUILTIN_GLOBALS_METHODDEF
30323022 BUILTIN_HASATTR_METHODDEF
30333023 BUILTIN_HASH_METHODDEF
@@ -3036,13 +3026,13 @@ static PyMethodDef builtin_methods[] = {
30363026 BUILTIN_INPUT_METHODDEF
30373027 BUILTIN_ISINSTANCE_METHODDEF
30383028 BUILTIN_ISSUBCLASS_METHODDEF
3039- BUILTIN_ITER_METHODDEF
3029+ { "iter" , _PyCFunction_CAST ( builtin_iter ), METH_FASTCALL , iter_doc },
30403030 BUILTIN_AITER_METHODDEF
30413031 BUILTIN_LEN_METHODDEF
30423032 BUILTIN_LOCALS_METHODDEF
30433033 {"max" , _PyCFunction_CAST (builtin_max ), METH_VARARGS | METH_KEYWORDS , max_doc },
30443034 {"min" , _PyCFunction_CAST (builtin_min ), METH_VARARGS | METH_KEYWORDS , min_doc },
3045- BUILTIN_NEXT_METHODDEF
3035+ { "next" , _PyCFunction_CAST ( builtin_next ), METH_FASTCALL , next_doc },
30463036 BUILTIN_ANEXT_METHODDEF
30473037 BUILTIN_OCT_METHODDEF
30483038 BUILTIN_ORD_METHODDEF
@@ -3053,7 +3043,7 @@ static PyMethodDef builtin_methods[] = {
30533043 BUILTIN_SETATTR_METHODDEF
30543044 BUILTIN_SORTED_METHODDEF
30553045 BUILTIN_SUM_METHODDEF
3056- BUILTIN_VARS_METHODDEF
3046+ { "vars" , builtin_vars , METH_VARARGS , vars_doc },
30573047 {NULL , NULL },
30583048};
30593049
0 commit comments