diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-27 22:00:11 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-27 22:00:11 +0000 |
commit | e71362d3dee9de626abb7d2d564550b5e59a1151 (patch) | |
tree | 1703c0a9f8d209b9dbff568a20f49a3541185dde /Python/bltinmodule.c | |
parent | Add version-added note twice for new difflib SequenceMatcher autojunk parameter. (diff) | |
download | cpython-e71362d3dee9de626abb7d2d564550b5e59a1151.tar.gz cpython-e71362d3dee9de626abb7d2d564550b5e59a1151.tar.bz2 cpython-e71362d3dee9de626abb7d2d564550b5e59a1151.zip |
Issue #10518: Bring back the callable() builtin.
Approved by Guido (BDFL) and Georg (RM).
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 46045192cfd..f374277f3dc 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}, |