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 asdfasdfasdfasdfasdfasdfasdf
Recipients asdfasdfasdfasdfasdfasdfasdf
Date 2010-08-27.13:53:24
SpamBayes Score 6.4694046e-09
Marked as misclassified No
Message-id <1282917207.25.0.718078039013.issue9702@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-08-27 13:53:27asdfasdfasdfasdfasdfasdfasdfsetrecipients: + asdfasdfasdfasdfasdfasdfasdf
2010-08-27 13:53:27asdfasdfasdfasdfasdfasdfasdfsetmessageid: <1282917207.25.0.718078039013.issue9702@psf.upfronthosting.co.za>
2010-08-27 13:53:25asdfasdfasdfasdfasdfasdfasdflinkissue9702 messages
2010-08-27 13:53:24asdfasdfasdfasdfasdfasdfasdfcreate