提交 94f417ba 编写于 作者: R Radostin Stoyanov 提交者: Daniel P. Berrangé

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: NDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: NRadostin Stoyanov <rstoyanov1@gmail.com>
上级 5e870cbd
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册