Bug in PyCallable_Check

Diez B. Roggisch deetsNOSPAM at web.de
Mon May 3 08:33:32 EDT 2004


Arkon wrote:

> Hello,
>  I encountered in a bug (or so I think) in the function
>  PyCallable_Check, Python C API.
> 
> The problem is that in Python code you can pass to a function that
> requests a function(pointer), types.FunctionType (Maybe other types
> too, didn't try though) which is in fact a type-type.
> 
> And then the PyCallable_Check won't *detect* that it's not a real
> function(pointer) passed...then later when you intend to run that
> function, you get an error.

FunctionType _is_ callable - in fact it can be used as a constructor:

>>> import types
>>> co = compile("print 1", "<string>", "exec")
>>> f = types.FunctionType(co, locals())
>>> f()
1
>>>

So basically  PyCallable_Check works  properly. And as python is a
dynamically typed language, I don't see how you can actually restrict the
type of values passed beyond that callable-check.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list