This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Chinmay.Kanchi
Recipients Chinmay.Kanchi
Date 2010-12-08.01:30:33
SpamBayes Score 2.3658298e-12
Marked as misclassified No
Message-id <1291771835.4.0.575373997099.issue10649@psf.upfronthosting.co.za>
In-reply-to
Content
Attempting to override a special method of an object of a builtin (like list) raises an AttributeError. This is obviously by design. However, doing the same to a user-defined function object seemingly replaces the function, but does not have the expected effect. In the interests of consistency, attempting to change a special method of a function object should raise an AttributeError stating that the property/method is read-only.

>>> a_list = list()
>>> a_list.__repr__ = lambda: '[]'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object attribute '__repr__' is read-only

>>> def f(): pass
>>> f.__repr__ = lambda: 'f'
>>> f.__repr__
<function <lambda> at 0x6482b0>
>>> repr(f) #would expect it to return 'f' since no error was raised
'<function f at 0x6481f0>'
>>> f.__repr__() #so the change is half-way made, inconsistent and possibly problematic
'f'
>>>
History
Date User Action Args
2010-12-08 01:30:35Chinmay.Kanchisetrecipients: + Chinmay.Kanchi
2010-12-08 01:30:35Chinmay.Kanchisetmessageid: <1291771835.4.0.575373997099.issue10649@psf.upfronthosting.co.za>
2010-12-08 01:30:33Chinmay.Kanchilinkissue10649 messages
2010-12-08 01:30:33Chinmay.Kanchicreate