Message123589
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'
>>> |
|
Date |
User |
Action |
Args |
2010-12-08 01:30:35 | Chinmay.Kanchi | set | recipients:
+ Chinmay.Kanchi |
2010-12-08 01:30:35 | Chinmay.Kanchi | set | messageid: <1291771835.4.0.575373997099.issue10649@psf.upfronthosting.co.za> |
2010-12-08 01:30:33 | Chinmay.Kanchi | link | issue10649 messages |
2010-12-08 01:30:33 | Chinmay.Kanchi | create | |
|