@@ -26,6 +26,11 @@ _Py_IDENTIFIER(stderr);
26
26
27
27
#include "clinic/bltinmodule.c.h"
28
28
29
+ /*[clinic input]
30
+ class callable "callableobject *" "&PyCallable_Type"
31
+ [clinic start generated code]*/
32
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=186f9359829695da]*/
33
+
29
34
static PyObject *
30
35
update_bases (PyObject * bases , PyObject * const * args , Py_ssize_t nargs )
31
36
{
@@ -454,9 +459,14 @@ builtin_bin(PyObject *module, PyObject *number)
454
459
return PyNumber_ToBase (number , 2 );
455
460
}
456
461
462
+ typedef struct {
463
+ PyObject_HEAD
464
+ } callableobject ;
465
+
457
466
458
467
/*[clinic input]
459
- callable as builtin_callable
468
+ @classmethod
469
+ callable.__new__ as callable_new
460
470
461
471
obj: object
462
472
/
@@ -468,12 +478,34 @@ __call__() method.
468
478
[clinic start generated code]*/
469
479
470
480
static PyObject *
471
- builtin_callable ( PyObject * module , PyObject * obj )
472
- /*[clinic end generated code: output=2b095d59d934cb7e input=1423bab99cc41f58 ]*/
481
+ callable_new_impl ( PyTypeObject * type , PyObject * obj )
482
+ /*[clinic end generated code: output=46784af2d6033e5a input=c0902a59d22a1a02 ]*/
473
483
{
474
484
return PyBool_FromLong ((long )PyCallable_Check (obj ));
475
485
}
476
486
487
+ static PyMethodDef callable_methods [] = {
488
+ {"__class_getitem__" , (PyCFunction )Py_GenericAlias , METH_O |METH_CLASS , PyDoc_STR ("See PEP 585" )},
489
+ {NULL , NULL } /* sentinel */
490
+ };
491
+
492
+ PyDoc_STRVAR (callable_doc ,
493
+ "Return whether the object is callable (i.e., some kind of function).\n\n\
494
+ Note that classes are callable, as are instances of classes with a\n\
495
+ __call__() method." );
496
+
497
+ PyTypeObject PyCallable_Type = {
498
+ PyVarObject_HEAD_INIT (& PyType_Type , 0 )
499
+ .tp_name = "callable" ,
500
+ .tp_basicsize = sizeof (callableobject ),
501
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
502
+ .tp_doc = callable_doc ,
503
+ .tp_methods = callable_methods ,
504
+ .tp_alloc = PyType_GenericAlloc ,
505
+ .tp_new = callable_new ,
506
+ .tp_free = PyObject_GC_Del ,
507
+ };
508
+
477
509
static PyObject *
478
510
builtin_breakpoint (PyObject * self , PyObject * const * args , Py_ssize_t nargs , PyObject * keywords )
479
511
{
@@ -2791,7 +2823,6 @@ static PyMethodDef builtin_methods[] = {
2791
2823
BUILTIN_ASCII_METHODDEF
2792
2824
BUILTIN_BIN_METHODDEF
2793
2825
{"breakpoint" , (PyCFunction )(void (* )(void ))builtin_breakpoint , METH_FASTCALL | METH_KEYWORDS , breakpoint_doc },
2794
- BUILTIN_CALLABLE_METHODDEF
2795
2826
BUILTIN_CHR_METHODDEF
2796
2827
BUILTIN_COMPILE_METHODDEF
2797
2828
BUILTIN_DELATTR_METHODDEF
@@ -2893,6 +2924,7 @@ _PyBuiltin_Init(PyThreadState *tstate)
2893
2924
SETBUILTIN ("complex" , & PyComplex_Type );
2894
2925
SETBUILTIN ("dict" , & PyDict_Type );
2895
2926
SETBUILTIN ("enumerate" , & PyEnum_Type );
2927
+ SETBUILTIN ("callable" , & PyCallable_Type );
2896
2928
SETBUILTIN ("filter" , & PyFilter_Type );
2897
2929
SETBUILTIN ("float" , & PyFloat_Type );
2898
2930
SETBUILTIN ("frozenset" , & PyFrozenSet_Type );
0 commit comments