summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2018-07-13 06:27:01 -0700
committerToshio Kuratomi <a.badger@gmail.com>2018-07-13 10:05:48 -0700
commita0748c08373fbfb932b2caf6b3dcb3958d5497e0 (patch)
treee128877b44cbd8c0ba014916f90eb8e3d22d1825
parent79ff2f5e9a7ad6c819f7156df747f449be01e6e2 (diff)
downloadansible-a0748c08373fbfb932b2caf6b3dcb3958d5497e0.tar.gz
Don't use deepcopy when creating attributes unless really needed
-rw-r--r--lib/ansible/playbook/attribute.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/ansible/playbook/attribute.py b/lib/ansible/playbook/attribute.py
index 644b368be6..65b33b300f 100644
--- a/lib/ansible/playbook/attribute.py
+++ b/lib/ansible/playbook/attribute.py
@@ -19,7 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-from copy import deepcopy
+from copy import copy, deepcopy
+
+
+_CONTAINERS = frozenset(('list', 'dict', 'set'))
class Attribute:
@@ -84,8 +87,17 @@ class Attribute:
self.extend = extend
self.prepend = prepend
- if default is not None and self.isa in ('list', 'dict', 'set'):
- self.default = deepcopy(default)
+ if default is not None and self.isa in _CONTAINERS:
+ if default:
+ self.default = deepcopy(default)
+ else:
+ # Don't need to deepcopy default if the container is empty
+ # Note: switch to try: except once Python3 is more widespread
+ if hasattr(default, 'copy'):
+ self.default = default.copy()
+ else:
+ # list on python2 does not have .copy()
+ self.default = copy(default)
else:
self.default = default