summaryrefslogtreecommitdiff
path: root/lib/ansible/inventory
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2020-05-05 10:55:26 -0700
committerToshio Kuratomi <a.badger@gmail.com>2020-05-06 09:56:40 -0700
commit39b394204870fda6de789809a3d69f58da3e7c31 (patch)
treed67f1496f9e697aad673a5990c887249bc966d07 /lib/ansible/inventory
parent852906fe7f44d832237d5d42fc5b3c38e6a25c59 (diff)
downloadansible-39b394204870fda6de789809a3d69f58da3e7c31.tar.gz
Remove left hand side slicing
Left hand side slicing is confusing and slower but maybe more memory efficient in some circumstances. There is one case where it adds to code safety: when it's used to substitute a different list in place of a slice of the original list and the original list could have been bound to a different variable in some other code. (The most likely case of this is when it's a global variable and some other code might import that variable name). Because of the confusion factor we think it should only be used for the safety case or where it's been benchmarked and shown to have some sort of documentatble improvement. At the moment, only one piece of code falls into those categories so this PR removes all the other instances of left hand side slicing.
Diffstat (limited to 'lib/ansible/inventory')
-rw-r--r--lib/ansible/inventory/manager.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py
index fa37532f7f..08f57701ea 100644
--- a/lib/ansible/inventory/manager.py
+++ b/lib/ansible/inventory/manager.py
@@ -381,27 +381,27 @@ class InventoryManager(object):
if pattern_hash not in self._hosts_patterns_cache:
patterns = split_host_pattern(pattern)
- hosts[:] = self._evaluate_patterns(patterns)
+ hosts = self._evaluate_patterns(patterns)
# mainly useful for hostvars[host] access
if not ignore_limits and self._subset:
# exclude hosts not in a subset, if defined
subset_uuids = set(s._uuid for s in self._evaluate_patterns(self._subset))
- hosts[:] = [h for h in hosts if h._uuid in subset_uuids]
+ hosts = [h for h in hosts if h._uuid in subset_uuids]
if not ignore_restrictions and self._restriction:
# exclude hosts mentioned in any restriction (ex: failed hosts)
- hosts[:] = [h for h in hosts if h.name in self._restriction]
+ hosts = [h for h in hosts if h.name in self._restriction]
self._hosts_patterns_cache[pattern_hash] = deduplicate_list(hosts)
# sort hosts list if needed (should only happen when called from strategy)
if order in ['sorted', 'reverse_sorted']:
- hosts[:] = sorted(self._hosts_patterns_cache[pattern_hash][:], key=attrgetter('name'), reverse=(order == 'reverse_sorted'))
+ hosts = sorted(self._hosts_patterns_cache[pattern_hash][:], key=attrgetter('name'), reverse=(order == 'reverse_sorted'))
elif order == 'reverse_inventory':
- hosts[:] = self._hosts_patterns_cache[pattern_hash][::-1]
+ hosts = self._hosts_patterns_cache[pattern_hash][::-1]
else:
- hosts[:] = self._hosts_patterns_cache[pattern_hash][:]
+ hosts = self._hosts_patterns_cache[pattern_hash][:]
if order == 'shuffle':
shuffle(hosts)
elif order not in [None, 'inventory']: