classification
Title: function with modified __name__ uses original name when there's an arg error
Type: behavior Stage: committed/rejected
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, erickt
Priority: normal Keywords:

Created on 2008-11-14 06:44 by erickt, last changed 2010-12-22 03:16 by r.david.murray. This issue is now closed.

Messages (2)
msg75853 - (view) Author: Erick Tryzelaar (erickt) Date: 2008-11-14 06:44
I ran into a case where I modified the __name__ attribute of a function 
and then didn't specify the right number of arguments, and I got a 
TypeError that used the original function name, as demonstrated here:

>>> def foo(): pass
... 
>>> foo.__name__ = 'bar'
>>> foo(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() takes no arguments (1 given)

I would have expected it to say "TypeError: bar() ...". I'm guessing 
that the interpreter isn't using the __name__ attribute in this case.
msg75886 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-14 21:39
This is because these errors use the code object's name attribute
(f.func_code.co_name) for error messages.
History
Date User Action Args
2010-12-22 03:16:06r.david.murraysetstatus: open -> closed
nosy: benjamin.peterson, erickt
resolution: invalid
stage: committed/rejected
2008-11-14 21:39:46benjamin.petersonsetpriority: normal
nosy: + benjamin.peterson
messages: + msg75886
2008-11-14 06:44:18ericktcreate