Re: Checking function calls

2006-03-08 Thread Joel Hedlund
If you have access to the source of the function you want to call (and know what kind of data types it wants in its args) you can raise something else for bad parameters, eg: class ArgTypeError(TypeError): def __init__(self,

Re: Checking function calls

2006-03-08 Thread Fredrik Tolf
On Mon, 2006-03-06 at 20:25 -0800, James Stroud wrote: Fredrik Tolf 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

Re: Checking function calls

2006-03-08 Thread Peter Otten
Fredrik Tolf wrote: # ... if callable(f): try: f(*cv[1:]) except TypeError: self.reply(err, argno) # ... However, this results in bugs in the server code that would cause TypeError to reply to the client that it had the wrong number of args, and I can't see

Re: Checking function calls

2006-03-08 Thread James Stroud
Fredrik Tolf wrote: On Mon, 2006-03-06 at 20:25 -0800, James Stroud wrote: Fredrik Tolf 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

Re: Checking function calls

2006-03-08 Thread James Stroud
Fredrik Tolf wrote: On Mon, 2006-03-06 at 20:25 -0800, James Stroud wrote: Fredrik Tolf 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

Re: Checking function calls

2006-03-07 Thread bruno at modulix
James Stroud wrote: (snip) Since python is weakly typed, s/weakly/dynamically/ (snip) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking function calls

2006-03-07 Thread Roy Smith
Fredrik Tolf python-list@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

Re: Checking function calls

2006-03-07 Thread gene tani
Roy Smith wrote: Fredrik Tolf python-list@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

Checking function calls

2006-03-06 Thread Fredrik Tolf
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

Re: Checking function calls

2006-03-06 Thread Ravi Teja
You can match if the list contains the legal number of arguments with. func_variable.func_code.co_argcount Type checking arguments has to be done manually since Python is a dynamic language. Perhaps, you could try some typechecking decorators. http://www.ilowe.net/software/typecheck/ From the

Re: Checking function calls

2006-03-06 Thread paul . dale
I will be out of the office from March 3rd to March 31st. In urgent cases please contact [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking function calls

2006-03-06 Thread Jay Parlar
On Mar 6, 2006, at 8:44 PM, James Stroud wrote: Since python is weakly typed, you will not be able to check what type of arguments a function expects. TypeErrors relating to the type of argemtns you pass will be raised inside the function only and not when it is called. I.e. there is no

Re: Checking function calls

2006-03-06 Thread James Stroud
Jay Parlar wrote: On Mar 6, 2006, at 8:44 PM, James Stroud wrote: Since python is weakly typed, you will not be able to check what type of arguments a function expects. TypeErrors relating to the type of argemtns you pass will be raised inside the function only and not when it is