Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Richard Damon
On 8/6/20 10:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? > Or the description of "if a tuple contains any mutable object either > directly or indirectly, it cannot be used as a key." in the document > is not completely correct? > The description

Re: Are instances of user-defined classes mutable?

2020-08-07 Thread Mats Wichmann
On 8/6/20 8:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? No, they're clealry mutable. > Or the description of "if a tuple contains any mutable object either directly > or indirectly, it cannot be used as a key." in the document is not >

Re:Re: Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
gt; me = mycls() >>> >>> me.a = 2 # mutable? >>> >>> {(1, me): 'mycls'} >>> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> >>> >>> >>> >>> So are instances of user-de

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread David Lowry-Duda
t; placed into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x022824DAD

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
, me): 'mycls'} >> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >> >>> >> >> >> So are instances of user-defined classes mutable or immutable? >> > user class instances are clearly mutable, and in my python 3.8

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Ethan Furman
On 8/6/20 7:40 AM, Robin Becker wrote: On 06/08/2020 05:17, ZHAOWANCHENG wrote: So are instances of user-defined classes mutable or immutable? user class instances are clearly mutable, and in my python 3.8 you can do horrid things like this > > [snip buggy/incorrect uses of __hash__

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Richard Damon
hat as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x0000022824DAD668>): '

Re: Are instances of user-defined classes mutable?

2020-08-06 Thread Robin Becker
of a dict: >>> class mycls(object): ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are instances of user

Are instances of user-defined classes mutable?

2020-08-06 Thread ZHAOWANCHENG
: ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'} >>> So are instances of user-defined classes mutable or immutable? -- https://mail.python.org/mailman/listinfo/python-list