Function name unchanged in error message
Jean-Michel Pichavant
jeanmichel at sequans.com
Fri Jan 29 08:44:49 EST 2010
andrew cooke wrote:
> Is there any way to change the name of the function in an error
> message? In the example below I'd like the error to refer to bar(),
> for example (the motivation is related function decorators - I'd like
> the wrapper function to give the same name)
>
>
>>>> def foo():
>>>>
> ... return 7
> ...
>
>>>> foo.__name__ = 'bar'
>>>> foo(123)
>>>>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: foo() takes no arguments (1 given)
>
> Thanks,
> Andrew
>
In [9]: def foo():
...: return 7
...:
In [10]: bar = foo
In [11]: bar(54)
TypeError: foo() takes no arguments (1 given)
JM
More information about the Python-list
mailing list