Commit a40112b0 authored by Stefan Behnel's avatar Stefan Behnel

optimise built-in callable() function

parent bd50b09a
......@@ -333,6 +333,8 @@ builtin_function_table = [
],
is_strict_signature = True)),
BuiltinFunction('abs', "O", "O", "PyNumber_Absolute"),
BuiltinFunction('callable', "O", "b", "__Pyx_PyCallable_Check",
utility_code = UtilityCode.load_cached("CallableCheck", "ObjectHandling.c")),
#('chr', "", "", ""),
#('cmp', "", "", "", ""), # int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
#('compile', "", "", ""), # PyObject* Py_CompileString( char *str, char *filename, int start)
......
......@@ -432,3 +432,11 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
Py_TYPE(obj)->tp_name, type->tp_name);
return 0;
}
/////////////// CallableCheck.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyCallable_Check(obj) ((obj)->ob_type->tp_call != NULL)
#else
#define __Pyx_PyCallable_Check(obj) PyCallable_Check(obj)
#endif
# mode: run
# tag: builtin, callable
cimport cython
@cython.test_assert_path_exists("//SimpleCallNode[@type.is_pyobject = False]")
def test_callable(x):
"""
>>> test_callable(None)
False
>>> test_callable('ABC')
False
>>> test_callable(int)
True
>>> test_callable(test_callable)
True
"""
b = callable(x)
return b
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment