diff options
author | Guido van Rossum <guido@python.org> | 1995-01-26 00:38:22 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-26 00:38:22 (GMT) |
commit | 49b11fed7009804a85740c237fe204bd4baab8b2 (patch) | |
tree | f2f76bba780c83e20cd5b6d47ab82e1b7f14c7bc /Objects | |
parent | f8803dd6c3089f4dcbda061fd567acd55995d9f4 (diff) | |
download | cpython-49b11fed7009804a85740c237fe204bd4baab8b2.zip cpython-49b11fed7009804a85740c237fe204bd4baab8b2.tar.gz cpython-49b11fed7009804a85740c237fe204bd4baab8b2.tar.bz2 |
move callable() here
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 63c55ce..73353e4 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -386,6 +386,35 @@ coerce(pv, pw) } +/* Test whether an object can be called */ + +int +callable(x) + object *x; +{ + if (x == NULL) + return 0; + if (x->ob_type->tp_call != NULL || + is_funcobject(x) || + is_instancemethodobject(x) || + is_methodobject(x) || + is_classobject(x)) + return 1; + if (is_instanceobject(x)) { + object *call = getattr(x, "__call__"); + if (call == NULL) { + err_clear(); + return 0; + } + /* Could test recursively but don't, for fear of endless + recursion if some joker sets self.__call__ = self */ + DECREF(call); + return 1; + } + return 0; +} + + /* NoObject is usable as a non-NULL undefined value, used by the macro None. There is (and should be!) no way to create other objects of this type, |