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