New submission from Arturo Inzunza <inzu...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue35439>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to