@@ -840,33 +840,31 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
840
840
return result ;
841
841
}
842
842
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 */
863
844
static 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 )
866
846
{
847
+ PyObject * arg = NULL ;
848
+
849
+ if (!PyArg_UnpackTuple (args , "dir" , 0 , 1 , & arg ))
850
+ return NULL ;
867
851
return PyObject_Dir (arg );
868
852
}
869
853
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
+
870
868
/*[clinic input]
871
869
divmod as builtin_divmod
872
870
@@ -1136,39 +1134,36 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
1136
1134
}
1137
1135
1138
1136
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 */
1154
1138
static 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 )
1158
1140
{
1159
- PyObject * result ;
1141
+ PyObject * v , * name , * result ;
1142
+
1143
+ if (!_PyArg_CheckPositional ("getattr" , nargs , 2 , 3 ))
1144
+ return NULL ;
1160
1145
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 );
1164
1152
}
1165
1153
}
1166
1154
else {
1167
- result = PyObject_GetAttr (object , name );
1155
+ result = PyObject_GetAttr (v , name );
1168
1156
}
1169
1157
return result ;
1170
1158
}
1171
1159
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
+
1172
1167
1173
1168
/*[clinic input]
1174
1169
globals as builtin_globals
@@ -1480,43 +1475,34 @@ PyTypeObject PyMap_Type = {
1480
1475
};
1481
1476
1482
1477
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 */
1496
1479
static 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 )
1500
1481
{
1501
- PyObject * res ;
1482
+ PyObject * it , * res ;
1483
+
1484
+ if (!_PyArg_CheckPositional ("next" , nargs , 1 , 2 ))
1485
+ return NULL ;
1502
1486
1503
- if (!PyIter_Check (iterator )) {
1487
+ it = args [0 ];
1488
+ if (!PyIter_Check (it )) {
1504
1489
PyErr_Format (PyExc_TypeError ,
1505
1490
"'%.200s' object is not an iterator" ,
1506
- Py_TYPE (iterator )-> tp_name );
1491
+ Py_TYPE (it )-> tp_name );
1507
1492
return NULL ;
1508
1493
}
1509
1494
1510
- res = (* Py_TYPE (iterator )-> tp_iternext )(iterator );
1495
+ res = (* Py_TYPE (it )-> tp_iternext )(it );
1511
1496
if (res != NULL ) {
1512
1497
return res ;
1513
- } else if (default_value != NULL ) {
1498
+ } else if (nargs > 1 ) {
1499
+ PyObject * def = args [1 ];
1514
1500
if (PyErr_Occurred ()) {
1515
1501
if (!PyErr_ExceptionMatches (PyExc_StopIteration ))
1516
1502
return NULL ;
1517
1503
PyErr_Clear ();
1518
1504
}
1519
- return Py_NewRef (default_value );
1505
+ return Py_NewRef (def );
1520
1506
} else if (PyErr_Occurred ()) {
1521
1507
return NULL ;
1522
1508
} else {
@@ -1525,6 +1511,12 @@ builtin_next_impl(PyObject *module, PyObject *iterator,
1525
1511
}
1526
1512
}
1527
1513
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
+
1528
1520
1529
1521
/*[clinic input]
1530
1522
setattr as builtin_setattr
@@ -1617,33 +1609,34 @@ builtin_hex(PyObject *module, PyObject *number)
1617
1609
}
1618
1610
1619
1611
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 */
1633
1613
static 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 )
1636
1615
{
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 )) {
1640
1624
PyErr_SetString (PyExc_TypeError ,
1641
- "iter(object, sentinel ): object must be callable" );
1625
+ "iter(v, w ): v must be callable" );
1642
1626
return NULL ;
1643
1627
}
1644
- return PyCallIter_New (object , sentinel );
1628
+ PyObject * sentinel = args [1 ];
1629
+ return PyCallIter_New (v , sentinel );
1645
1630
}
1646
1631
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
+
1647
1640
1648
1641
/*[clinic input]
1649
1642
aiter as builtin_aiter
@@ -2443,36 +2436,33 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
2443
2436
}
2444
2437
2445
2438
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 */
2458
2440
static 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 )
2461
2442
{
2443
+ PyObject * v = NULL ;
2462
2444
PyObject * d ;
2463
2445
2464
- if (object == NULL ) {
2446
+ if (!PyArg_UnpackTuple (args , "vars" , 0 , 1 , & v ))
2447
+ return NULL ;
2448
+ if (v == NULL ) {
2465
2449
d = _PyEval_GetFrameLocals ();
2466
2450
}
2467
2451
else {
2468
- if (_PyObject_LookupAttr (object , & _Py_ID (__dict__ ), & d ) == 0 ) {
2452
+ if (_PyObject_LookupAttr (v , & _Py_ID (__dict__ ), & d ) == 0 ) {
2469
2453
PyErr_SetString (PyExc_TypeError ,
2470
2454
"vars() argument must have __dict__ attribute" );
2471
2455
}
2472
2456
}
2473
2457
return d ;
2474
2458
}
2475
2459
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
+
2476
2466
2477
2467
/*[clinic input]
2478
2468
sum as builtin_sum
@@ -3024,12 +3014,12 @@ static PyMethodDef builtin_methods[] = {
3024
3014
BUILTIN_CHR_METHODDEF
3025
3015
BUILTIN_COMPILE_METHODDEF
3026
3016
BUILTIN_DELATTR_METHODDEF
3027
- BUILTIN_DIR_METHODDEF
3017
+ { "dir" , builtin_dir , METH_VARARGS , dir_doc },
3028
3018
BUILTIN_DIVMOD_METHODDEF
3029
3019
BUILTIN_EVAL_METHODDEF
3030
3020
BUILTIN_EXEC_METHODDEF
3031
3021
BUILTIN_FORMAT_METHODDEF
3032
- BUILTIN_GETATTR_METHODDEF
3022
+ { "getattr" , _PyCFunction_CAST ( builtin_getattr ), METH_FASTCALL , getattr_doc },
3033
3023
BUILTIN_GLOBALS_METHODDEF
3034
3024
BUILTIN_HASATTR_METHODDEF
3035
3025
BUILTIN_HASH_METHODDEF
@@ -3038,13 +3028,13 @@ static PyMethodDef builtin_methods[] = {
3038
3028
BUILTIN_INPUT_METHODDEF
3039
3029
BUILTIN_ISINSTANCE_METHODDEF
3040
3030
BUILTIN_ISSUBCLASS_METHODDEF
3041
- BUILTIN_ITER_METHODDEF
3031
+ { "iter" , _PyCFunction_CAST ( builtin_iter ), METH_FASTCALL , iter_doc },
3042
3032
BUILTIN_AITER_METHODDEF
3043
3033
BUILTIN_LEN_METHODDEF
3044
3034
BUILTIN_LOCALS_METHODDEF
3045
3035
{"max" , _PyCFunction_CAST (builtin_max ), METH_VARARGS | METH_KEYWORDS , max_doc },
3046
3036
{"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 },
3048
3038
BUILTIN_ANEXT_METHODDEF
3049
3039
BUILTIN_OCT_METHODDEF
3050
3040
BUILTIN_ORD_METHODDEF
@@ -3055,7 +3045,7 @@ static PyMethodDef builtin_methods[] = {
3055
3045
BUILTIN_SETATTR_METHODDEF
3056
3046
BUILTIN_SORTED_METHODDEF
3057
3047
BUILTIN_SUM_METHODDEF
3058
- BUILTIN_VARS_METHODDEF
3048
+ { "vars" , builtin_vars , METH_VARARGS , vars_doc },
3059
3049
{NULL , NULL },
3060
3050
};
3061
3051
0 commit comments