WmiClass: Don't share "versions" between instances

Lists in Python are mutable and when used as a default value of a
parameter for class constructor, its value will be shared between
all class instances.

Example:

	class Test:
	    def __init__(self, mylist=[]):
	        self.mylist = mylist

	A = Test()
	B = Test()
	A.mylist.append("mylist from instance A")
	print(B.mylist) # Will print ['mylist from instance A']

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This commit is contained in:
Radostin Stoyanov 2018-03-20 06:48:55 +00:00 committed by Daniel P. Berrangé
parent 5e870cbda4
commit 94f417baa9

View File

@ -44,9 +44,9 @@ class WmiClass:
to.
"""
def __init__(self, name, versions = []):
def __init__(self, name, versions=None):
self.name = name
self.versions = versions
self.versions = versions if versions else list()
self.common = None