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 bolt
Recipients bolt
Date 2010-05-19.00:35:31
SpamBayes Score 9.918515e-06
Marked as misclassified No
Message-id <1274229335.16.0.189072837052.issue8762@psf.upfronthosting.co.za>
In-reply-to
Content
After debugging for a while I finally released that I stumbled across a Python bug (at least I believe it is). Here is a proof of concept that produces the issue:

!/usr/bin/python

class blah:

    def __init__(self, items=[]):
        self.items = items

a = blah()
b = blah()

a.items.append("apples")
b.items.append("oranges")

print a.items
print b.items
print id(a.items)
print id(b.items)


and here is the output when the program is run:

root@x:~# python pythonbug.py
['apples', 'oranges']
['apples', 'oranges']
135923500
135923500
root@x:~#

as you can see the 'items' reference is the same for both objects even though they are different objects. I checked the manual and I couldn't find anything explaining such behavior. Can this possibly be correct?

My python info:

Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48)
History
Date User Action Args
2010-05-19 00:35:35boltsetrecipients: + bolt
2010-05-19 00:35:35boltsetmessageid: <1274229335.16.0.189072837052.issue8762@psf.upfronthosting.co.za>
2010-05-19 00:35:32boltlinkissue8762 messages
2010-05-19 00:35:31boltcreate