Re: other ways to check for <type 'function'>?
Christophe a écrit :
Or even worse. Since we have :
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: cannot concatenate 'str' and 'int' objects
All of them are TypeError exceptions. It is extremly dangerous to put a
try except TypeError clause around a function call to catch the case
where the function object isn't a callable :/
Christophe a écrit :
Sybren Stuvel a écrit :
>
And what if the function has an error and calls a non callable object ?
>Christophe enlightened us with:
>>
>That depends on the exception you're catching, doesn't it?
>>I don't think it's a good idea because when you place a try catch
>>block around a function call, you'll catch any exception thrown by
>>the function itself and not only the "cannot be called" exception.
>>block around a function call, you'll catch any exception thrown by
>>the function itself and not only the "cannot be called" exception.
>That depends on the exception you're catching, doesn't it?
And what if the function has an error and calls a non callable object ?
>>None()
File "<stdin>", line 1, in ?
TypeError: 'NoneType' object is not callable
>>1+""
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>""+1
File "<stdin>", line 1, in ?
TypeError: cannot concatenate 'str' and 'int' objects
All of them are TypeError exceptions. It is extremly dangerous to put a
try except TypeError clause around a function call to catch the case
where the function object isn't a callable :/
Comment