summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-11-27 22:00:11 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-11-27 22:00:11 (GMT)
commite71362d3dee9de626abb7d2d564550b5e59a1151 (patch)
tree1703c0a9f8d209b9dbff568a20f49a3541185dde /Python
parentdc9b17d922ba30cbfbcc767dfb0738b6bf66015d (diff)
downloadcpython-e71362d3dee9de626abb7d2d564550b5e59a1151.zip
cpython-e71362d3dee9de626abb7d2d564550b5e59a1151.tar.gz
cpython-e71362d3dee9de626abb7d2d564550b5e59a1151.tar.bz2
Issue #10518: Bring back the callable() builtin.
Approved by Guido (BDFL) and Georg (RM).
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 4604519..f374277 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -311,6 +311,20 @@ PyDoc_STRVAR(bin_doc,
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 @@ static PyMethodDef builtin_methods[] = {
{"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},