Checking function calls

gene tani gene.tani at gmail.com
Tue Mar 7 09:12:59 EST 2006


Roy Smith wrote:
> Fredrik Tolf  <python-list at python.org> wrote:
> >If I have a variable which points to a function, can I check if certain
> >argument list matches what the function wants before or when calling it?
> >
> >Currently, I'm trying to catch a TypeError when calling the function
> >(since that is what is raised when trying to call it with an illegal
> >list), but that has the rather undesirable side effect of also catching
> >any TypeErrors raised inside the function. Is there a way to avoid that?
>
> The only way is to read the documentation for the function (or, the
> source code).
>
> Can you be a little more specific about what you're trying to do?  Can
> you post your code?

if you know ahead of runtime which methods are at issue and what method
signatures you want, multimethod decorators, maybe?
http://www.artima.com/weblogs/viewpost.jsp?thread=101605
(read comments: PJE, ian bicking

or you can arg-test inside the method, which isn't much fun
http://www.python.org/doc/faq/programming.html#how-can-i-overload-constructors-or-methods-in-python




More information about the Python-list mailing list