[New-bugs-announce] [issue35439] New class instance not initializing variables of type list
Arturo Inzunza
report at bugs.python.org
Fri Dec 7 19:26:46 EST 2018
New submission from Arturo Inzunza <inzunzo at gmail.com>:
List type variables in a class are not reset on new instances of the class.
Example:
class Klazz:
lst = []
def __init__(self, va):
print(self.lst)
self.lst.append(va)
k = Klazz(1)
[] -> This is correct as the lst value is empty on class instantiation
k2 = Klazz(2)
[1] -> This is wrong, a totally new instance of the class retains the value of a previous class instance lst variable
k3 = Klazz(3)
[1, 2] -> And so on... new instances all share the same list
----------
messages: 331370
nosy: Arturo Inzunza
priority: normal
severity: normal
status: open
title: New class instance not initializing variables of type list
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35439>
_______________________________________
More information about the New-bugs-announce
mailing list