@@ -837,31 +837,33 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
837
837
return result ;
838
838
}
839
839
840
- /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
840
+ /*[clinic input]
841
+ dir as builtin_dir
842
+
843
+ arg: object = NULL
844
+ /
845
+
846
+ Show attributes of an object.
847
+
848
+ If called without an argument, return the names in the current scope.
849
+ Else, return an alphabetized list of names comprising (some of) the attributes
850
+ of the given object, and of attributes reachable from it.
851
+ If the object supplies a method named __dir__, it will be used; otherwise
852
+ the default dir() logic is used and returns:
853
+ for a module object: the module's attributes.
854
+ for a class object: its attributes, and recursively the attributes
855
+ of its bases.
856
+ for any other object: its attributes, its class's attributes, and
857
+ recursively the attributes of its class's base classes.
858
+ [clinic start generated code]*/
859
+
841
860
static PyObject *
842
- builtin_dir (PyObject * self , PyObject * args )
861
+ builtin_dir_impl (PyObject * module , PyObject * arg )
862
+ /*[clinic end generated code: output=24f2c7a52c1e3b08 input=ed6d6ccb13d52251]*/
843
863
{
844
- PyObject * arg = NULL ;
845
-
846
- if (!PyArg_UnpackTuple (args , "dir" , 0 , 1 , & arg ))
847
- return NULL ;
848
864
return PyObject_Dir (arg );
849
865
}
850
866
851
- PyDoc_STRVAR (dir_doc ,
852
- "dir([object]) -> list of strings\n"
853
- "\n"
854
- "If called without an argument, return the names in the current scope.\n"
855
- "Else, return an alphabetized list of names comprising (some of) the attributes\n"
856
- "of the given object, and of attributes reachable from it.\n"
857
- "If the object supplies a method named __dir__, it will be used; otherwise\n"
858
- "the default dir() logic is used and returns:\n"
859
- " for a module object: the module's attributes.\n"
860
- " for a class object: its attributes, and recursively the attributes\n"
861
- " of its bases.\n"
862
- " for any other object: its attributes, its class's attributes, and\n"
863
- " recursively the attributes of its class's base classes." );
864
-
865
867
/*[clinic input]
866
868
divmod as builtin_divmod
867
869
@@ -1109,36 +1111,39 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
1109
1111
}
1110
1112
1111
1113
1112
- /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
1114
+ /*[clinic input]
1115
+ getattr as builtin_getattr
1116
+
1117
+ object: object
1118
+ name: object
1119
+ default: object = NULL
1120
+ /
1121
+
1122
+ Get a named attribute from an object.
1123
+
1124
+ getattr(x, 'y') is equivalent to x.y
1125
+ When a default argument is given, it is returned when the attribute doesn't
1126
+ exist; without it, an exception is raised in that case.
1127
+ [clinic start generated code]*/
1128
+
1113
1129
static PyObject *
1114
- builtin_getattr (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
1130
+ builtin_getattr_impl (PyObject * module , PyObject * object , PyObject * name ,
1131
+ PyObject * default_value )
1132
+ /*[clinic end generated code: output=74ad0e225e3f701c input=d7562cd4c3556171]*/
1115
1133
{
1116
- PyObject * v , * name , * result ;
1117
-
1118
- if (!_PyArg_CheckPositional ("getattr" , nargs , 2 , 3 ))
1119
- return NULL ;
1134
+ PyObject * result ;
1120
1135
1121
- v = args [0 ];
1122
- name = args [1 ];
1123
- if (nargs > 2 ) {
1124
- if (_PyObject_LookupAttr (v , name , & result ) == 0 ) {
1125
- PyObject * dflt = args [2 ];
1126
- return Py_NewRef (dflt );
1136
+ if (default_value != NULL ) {
1137
+ if (_PyObject_LookupAttr (object , name , & result ) == 0 ) {
1138
+ return Py_NewRef (default_value );
1127
1139
}
1128
1140
}
1129
1141
else {
1130
- result = PyObject_GetAttr (v , name );
1142
+ result = PyObject_GetAttr (object , name );
1131
1143
}
1132
1144
return result ;
1133
1145
}
1134
1146
1135
- PyDoc_STRVAR (getattr_doc ,
1136
- "getattr(object, name[, default]) -> value\n\
1137
- \n\
1138
- Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\
1139
- When a default argument is given, it is returned when the attribute doesn't\n\
1140
- exist; without it, an exception is raised in that case." );
1141
-
1142
1147
1143
1148
/*[clinic input]
1144
1149
globals as builtin_globals
@@ -1450,34 +1455,43 @@ PyTypeObject PyMap_Type = {
1450
1455
};
1451
1456
1452
1457
1453
- /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
1458
+ /*[clinic input]
1459
+ next as builtin_next
1460
+
1461
+ iterator: object
1462
+ default: object = NULL
1463
+ /
1464
+
1465
+ Return the next item from the iterator.
1466
+
1467
+ If default is given and the iterator is exhausted,
1468
+ it is returned instead of raising StopIteration.
1469
+ [clinic start generated code]*/
1470
+
1454
1471
static PyObject *
1455
- builtin_next (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
1472
+ builtin_next_impl (PyObject * module , PyObject * iterator ,
1473
+ PyObject * default_value )
1474
+ /*[clinic end generated code: output=a38a94eeb447fef9 input=180f9984f182020f]*/
1456
1475
{
1457
- PyObject * it , * res ;
1458
-
1459
- if (!_PyArg_CheckPositional ("next" , nargs , 1 , 2 ))
1460
- return NULL ;
1476
+ PyObject * res ;
1461
1477
1462
- it = args [0 ];
1463
- if (!PyIter_Check (it )) {
1478
+ if (!PyIter_Check (iterator )) {
1464
1479
PyErr_Format (PyExc_TypeError ,
1465
1480
"'%.200s' object is not an iterator" ,
1466
- Py_TYPE (it )-> tp_name );
1481
+ Py_TYPE (iterator )-> tp_name );
1467
1482
return NULL ;
1468
1483
}
1469
1484
1470
- res = (* Py_TYPE (it )-> tp_iternext )(it );
1485
+ res = (* Py_TYPE (iterator )-> tp_iternext )(iterator );
1471
1486
if (res != NULL ) {
1472
1487
return res ;
1473
- } else if (nargs > 1 ) {
1474
- PyObject * def = args [1 ];
1488
+ } else if (default_value != NULL ) {
1475
1489
if (PyErr_Occurred ()) {
1476
1490
if (!PyErr_ExceptionMatches (PyExc_StopIteration ))
1477
1491
return NULL ;
1478
1492
PyErr_Clear ();
1479
1493
}
1480
- return Py_NewRef (def );
1494
+ return Py_NewRef (default_value );
1481
1495
} else if (PyErr_Occurred ()) {
1482
1496
return NULL ;
1483
1497
} else {
@@ -1486,12 +1500,6 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1486
1500
}
1487
1501
}
1488
1502
1489
- PyDoc_STRVAR (next_doc ,
1490
- "next(iterator[, default])\n\
1491
- \n\
1492
- Return the next item from the iterator. If default is given and the iterator\n\
1493
- is exhausted, it is returned instead of raising StopIteration." );
1494
-
1495
1503
1496
1504
/*[clinic input]
1497
1505
setattr as builtin_setattr
@@ -1584,34 +1592,33 @@ builtin_hex(PyObject *module, PyObject *number)
1584
1592
}
1585
1593
1586
1594
1587
- /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
1595
+ /*[clinic input]
1596
+ iter as builtin_iter
1597
+
1598
+ object: object
1599
+ sentinel: object = NULL
1600
+ /
1601
+
1602
+ Get an iterator from an object.
1603
+
1604
+ In the first form, the argument must supply its own iterator, or be a sequence.
1605
+ In the second form, the callable is called until it returns the sentinel.
1606
+ [clinic start generated code]*/
1607
+
1588
1608
static PyObject *
1589
- builtin_iter (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
1609
+ builtin_iter_impl (PyObject * module , PyObject * object , PyObject * sentinel )
1610
+ /*[clinic end generated code: output=12cf64203c195a94 input=a5d64d9d81880ba6]*/
1590
1611
{
1591
- PyObject * v ;
1592
-
1593
- if (!_PyArg_CheckPositional ("iter" , nargs , 1 , 2 ))
1594
- return NULL ;
1595
- v = args [0 ];
1596
- if (nargs == 1 )
1597
- return PyObject_GetIter (v );
1598
- if (!PyCallable_Check (v )) {
1612
+ if (sentinel == NULL )
1613
+ return PyObject_GetIter (object );
1614
+ if (!PyCallable_Check (object )) {
1599
1615
PyErr_SetString (PyExc_TypeError ,
1600
- "iter(v, w ): v must be callable" );
1616
+ "iter(object, sentinel ): object must be callable" );
1601
1617
return NULL ;
1602
1618
}
1603
- PyObject * sentinel = args [1 ];
1604
- return PyCallIter_New (v , sentinel );
1619
+ return PyCallIter_New (object , sentinel );
1605
1620
}
1606
1621
1607
- PyDoc_STRVAR (iter_doc ,
1608
- "iter(iterable) -> iterator\n\
1609
- iter(callable, sentinel) -> iterator\n\
1610
- \n\
1611
- Get an iterator from an object. In the first form, the argument must\n\
1612
- supply its own iterator, or be a sequence.\n\
1613
- In the second form, the callable is called until it returns the sentinel." );
1614
-
1615
1622
1616
1623
/*[clinic input]
1617
1624
aiter as builtin_aiter
@@ -2390,33 +2397,36 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
2390
2397
}
2391
2398
2392
2399
2393
- /* AC: cannot convert yet, as needs PEP 457 group support in inspect */
2400
+ /*[clinic input]
2401
+ vars as builtin_vars
2402
+
2403
+ object: object = NULL
2404
+ /
2405
+
2406
+ Show vars.
2407
+
2408
+ Without arguments, equivalent to locals().
2409
+ With an argument, equivalent to object.__dict__.
2410
+ [clinic start generated code]*/
2411
+
2394
2412
static PyObject *
2395
- builtin_vars (PyObject * self , PyObject * args )
2413
+ builtin_vars_impl (PyObject * module , PyObject * object )
2414
+ /*[clinic end generated code: output=840a7f64007a3e0a input=80cbdef9182c4ba3]*/
2396
2415
{
2397
- PyObject * v = NULL ;
2398
2416
PyObject * d ;
2399
2417
2400
- if (!PyArg_UnpackTuple (args , "vars" , 0 , 1 , & v ))
2401
- return NULL ;
2402
- if (v == NULL ) {
2418
+ if (object == NULL ) {
2403
2419
d = Py_XNewRef (PyEval_GetLocals ());
2404
2420
}
2405
2421
else {
2406
- if (_PyObject_LookupAttr (v , & _Py_ID (__dict__ ), & d ) == 0 ) {
2422
+ if (_PyObject_LookupAttr (object , & _Py_ID (__dict__ ), & d ) == 0 ) {
2407
2423
PyErr_SetString (PyExc_TypeError ,
2408
2424
"vars() argument must have __dict__ attribute" );
2409
2425
}
2410
2426
}
2411
2427
return d ;
2412
2428
}
2413
2429
2414
- PyDoc_STRVAR (vars_doc ,
2415
- "vars([object]) -> dictionary\n\
2416
- \n\
2417
- Without arguments, equivalent to locals().\n\
2418
- With an argument, equivalent to object.__dict__." );
2419
-
2420
2430
2421
2431
/*[clinic input]
2422
2432
sum as builtin_sum
@@ -2966,12 +2976,12 @@ static PyMethodDef builtin_methods[] = {
2966
2976
BUILTIN_CHR_METHODDEF
2967
2977
BUILTIN_COMPILE_METHODDEF
2968
2978
BUILTIN_DELATTR_METHODDEF
2969
- { "dir" , builtin_dir , METH_VARARGS , dir_doc },
2979
+ BUILTIN_DIR_METHODDEF
2970
2980
BUILTIN_DIVMOD_METHODDEF
2971
2981
BUILTIN_EVAL_METHODDEF
2972
2982
BUILTIN_EXEC_METHODDEF
2973
2983
BUILTIN_FORMAT_METHODDEF
2974
- { "getattr" , _PyCFunction_CAST ( builtin_getattr ), METH_FASTCALL , getattr_doc },
2984
+ BUILTIN_GETATTR_METHODDEF
2975
2985
BUILTIN_GLOBALS_METHODDEF
2976
2986
BUILTIN_HASATTR_METHODDEF
2977
2987
BUILTIN_HASH_METHODDEF
@@ -2980,13 +2990,13 @@ static PyMethodDef builtin_methods[] = {
2980
2990
BUILTIN_INPUT_METHODDEF
2981
2991
BUILTIN_ISINSTANCE_METHODDEF
2982
2992
BUILTIN_ISSUBCLASS_METHODDEF
2983
- { "iter" , _PyCFunction_CAST ( builtin_iter ), METH_FASTCALL , iter_doc },
2993
+ BUILTIN_ITER_METHODDEF
2984
2994
BUILTIN_AITER_METHODDEF
2985
2995
BUILTIN_LEN_METHODDEF
2986
2996
BUILTIN_LOCALS_METHODDEF
2987
2997
{"max" , _PyCFunction_CAST (builtin_max ), METH_VARARGS | METH_KEYWORDS , max_doc },
2988
2998
{"min" , _PyCFunction_CAST (builtin_min ), METH_VARARGS | METH_KEYWORDS , min_doc },
2989
- { "next" , _PyCFunction_CAST ( builtin_next ), METH_FASTCALL , next_doc },
2999
+ BUILTIN_NEXT_METHODDEF
2990
3000
BUILTIN_ANEXT_METHODDEF
2991
3001
BUILTIN_OCT_METHODDEF
2992
3002
BUILTIN_ORD_METHODDEF
@@ -2997,7 +3007,7 @@ static PyMethodDef builtin_methods[] = {
2997
3007
BUILTIN_SETATTR_METHODDEF
2998
3008
BUILTIN_SORTED_METHODDEF
2999
3009
BUILTIN_SUM_METHODDEF
3000
- { "vars" , builtin_vars , METH_VARARGS , vars_doc },
3010
+ BUILTIN_VARS_METHODDEF
3001
3011
{NULL , NULL },
3002
3012
};
3003
3013
0 commit comments