Message115074
Python violates most users expectations via the modification differences of immutable and mutable objects in methods.
def foo(bar):
bar = bar + bar
def listy(bar):
bar = [1]
def dicty(bar):
bar['1'] = '1'
if __name__ == "__main__":
bar = 1
foo(bar)
print bar
baz = []
print baz
listy(baz)
print baz
dict_d = {}
print dict_d
dicty(dict_d)
print dict_d
this will output
1
[]
[]
{}
{'1': '1'}
So sure this is 'expected'(pass by reference vs new object - for immutable objects) but it sure isn't obvious.
I feel this is a bug in python core.
I think that the behaviour should be the same for *all* objects.
If it is pass by reference, *and* the item has to be able to be updated(I feel this breaks most people's expectations...) then the result of a modification to an object that is immutable should be that the pointer to the original now points to the resulting string.
Personally I do not want to be able to modify the dictionary as I did above like I did. |
|
Date |
User |
Action |
Args |
2010-08-27 13:53:27 | asdfasdfasdfasdfasdfasdfasdf | set | recipients:
+ asdfasdfasdfasdfasdfasdfasdf |
2010-08-27 13:53:27 | asdfasdfasdfasdfasdfasdfasdf | set | messageid: <1282917207.25.0.718078039013.issue9702@psf.upfronthosting.co.za> |
2010-08-27 13:53:25 | asdfasdfasdfasdfasdfasdfasdf | link | issue9702 messages |
2010-08-27 13:53:24 | asdfasdfasdfasdfasdfasdfasdf | create | |
|