Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 66521:1b77f2eb1606
Issue #10518: Bring back the callable() builtin.
Approved by Guido (BDFL) and Georg (RM).
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 27 Nov 2010 22:00:11 +0000 |
| parents | e8969fb822fc |
| children | 724920a015f7 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Sat Nov 27 20:52:14 2010 +0000 +++ b/Python/bltinmodule.c Sat Nov 27 22:00:11 2010 +0000 @@ -311,6 +311,20 @@ Return the binary representation of an integer or long integer."); +static PyObject * +builtin_callable(PyObject *self, PyObject *v) +{ + return PyBool_FromLong((long)PyCallable_Check(v)); +} + +PyDoc_STRVAR(callable_doc, +"callable(object) -> bool\n\ +\n\ +Return whether the object is callable (i.e., some kind of function).\n\ +Note that classes are callable, as are instances of classes with a\n\ +__call__() method."); + + typedef struct { PyObject_HEAD PyObject *func; @@ -2242,6 +2256,7 @@ {"any", builtin_any, METH_O, any_doc}, {"ascii", builtin_ascii, METH_O, ascii_doc}, {"bin", builtin_bin, METH_O, bin_doc}, + {"callable", builtin_callable, METH_O, callable_doc}, {"chr", builtin_chr, METH_VARARGS, chr_doc}, {"compile", (PyCFunction)builtin_compile, METH_VARARGS | METH_KEYWORDS, compile_doc}, {"delattr", builtin_delattr, METH_VARARGS, delattr_doc},
