From 94f417baa93ff1e120c065ba70daadce3c8cdd70 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Tue, 20 Mar 2018 06:48:55 +0000 Subject: [PATCH] WmiClass: Don't share "versions" between instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é Signed-off-by: Radostin Stoyanov --- src/hyperv/hyperv_wmi_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py index 6e98f0a89c..0dcd9e4383 100755 --- a/src/hyperv/hyperv_wmi_generator.py +++ b/src/hyperv/hyperv_wmi_generator.py @@ -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