mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-02 19:32:47 +00:00
attribute defaults that are containers are a copy
This is simpler way to prevent persistent containers across instances of classes that use field attributes
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
class Attribute:
|
||||
|
||||
@@ -32,6 +33,11 @@ class Attribute:
|
||||
self.priority = priority
|
||||
self.always_post_validate = always_post_validate
|
||||
|
||||
if default is not None and self.isa in ('list', 'dict', 'set'):
|
||||
self.default = deepcopy(default)
|
||||
else:
|
||||
self.default = default
|
||||
|
||||
def __eq__(self, other):
|
||||
return other.priority == self.priority
|
||||
|
||||
|
||||
Reference in New Issue
Block a user