From 9579113941c3db4167daa83173d7e6088ce09f8c Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Wed, 6 May 2020 21:45:02 -0500 Subject: [PATCH] Remove some no-op code from InventoryManager Change: - Remove some no-op code - Split up a somewhat complex line into two lines - Nuke an incorrect comment Test Plan: CI Signed-off-by: Rick Elrod --- lib/ansible/inventory/data.py | 1 - lib/ansible/inventory/manager.py | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/inventory/data.py b/lib/ansible/inventory/data.py index c87d9385642..84966ab2bd8 100644 --- a/lib/ansible/inventory/data.py +++ b/lib/ansible/inventory/data.py @@ -41,7 +41,6 @@ class InventoryData(object): def __init__(self): - # the inventory object holds a list of groups self.groups = {} self.hosts = {} diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 08f57701ea3..5606b2655ee 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -104,7 +104,9 @@ def split_host_pattern(pattern): """ if isinstance(pattern, list): - return list(itertools.chain(*map(split_host_pattern, pattern))) + results = (split_host_pattern(p) for p in pattern) + # flatten the results + return list(itertools.chain.from_iterable(results)) elif not isinstance(pattern, string_types): pattern = to_text(pattern, errors='surrogate_or_strict') @@ -580,7 +582,7 @@ class InventoryManager(object): def list_hosts(self, pattern="all"): """ return a list of hostnames for a pattern """ # FIXME: cache? - result = [h for h in self.get_hosts(pattern)] + result = self.get_hosts(pattern) # allow implicit localhost if pattern matches and no other results if len(result) == 0 and pattern in C.LOCALHOST: @@ -590,7 +592,7 @@ class InventoryManager(object): def list_groups(self): # FIXME: cache? - return sorted(self._inventory.groups.keys(), key=lambda x: x) + return sorted(self._inventory.groups.keys()) def restrict_to_hosts(self, restriction): """