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 Kevin Young
Recipients Kevin Young
Date 2020-02-05.06:35:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580884554.4.0.0450040370405.issue39556@roundup.psfhosted.org>
In-reply-to
Content
Test code:

class Test(object):
    def __init__(self, a={}):
        self._a = a
    
    def put(self, k, v):
        self._a[k] = v

if __name__ == '__main__':
    t1 = Test()
    t1.put('aa', '11')
    t1.put('bb', '22')
    
    t2 = Test()
    t2.put('cc', '33')
    for k, v in t2._a.items():
        print(k, '=', v)

Output:
aa = 11
bb = 22
cc = 33

The expected output should be:
cc = 33

My workaround:
self._a = dict(a)

I have tested on both Python 3.7.3 and 3.8.1, they share the same results.
I'm not sure if this is a bug or on-purpose feature of python. Could someone provide some guidance for me? Thank you.
History
Date User Action Args
2020-02-05 06:35:54Kevin Youngsetrecipients: + Kevin Young
2020-02-05 06:35:54Kevin Youngsetmessageid: <1580884554.4.0.0450040370405.issue39556@roundup.psfhosted.org>
2020-02-05 06:35:54Kevin Younglinkissue39556 messages
2020-02-05 06:35:53Kevin Youngcreate