From dcdb20d0f5ec0e9a3409c0d6f14d138f042129c9 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 2 Dec 2015 06:07:38 -0800 Subject: [PATCH] Provide a better comment for the object short-circuit A previous commit was landed over a -1 from a core reviewer that was concerned about the terse and flippant commit message that accompanied the commit. The substance of that objection was that there was no good explanation for why the change was made. Indeed, that why is likely useful for people looking at the code too, so add a more complete comment on the code in question. Change-Id: I1ff777393502edf4ef3ed595e47bfcf73be0e5e8 --- shade/_utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shade/_utils.py b/shade/_utils.py index 3a720efd4..ef436630b 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -121,11 +121,15 @@ def _get_entity(func, name_or_id, filters): A function that takes `name_or_id` and `filters` as parameters and returns a list of entities to filter. :param string name_or_id: - The name or ID of the entity being filtered. + The name or ID of the entity being filtered or a dict :param dict filters: A dictionary of meta data to use for further filtering. """ - # We've been passed a dict/object already, return it + # Sometimes in the control flow of shade, we already have an object + # fetched. Rather than then needing to pull the name or id out of that + # object, pass it in here and rely on caching to prevent us from making + # an additional call, it's simple enough to test to see if we got an + # object and just short-circuit return it. if hasattr(name_or_id, 'id'): return name_or_id entities = func(name_or_id, filters)