From de16ce42ef49c7067d23fcbe41a34f0558a2cd9b Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 17 Aug 2017 15:50:04 -0400 Subject: [PATCH] optimize reserved names warning --- lib/ansible/vars/reserved.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/vars/reserved.py b/lib/ansible/vars/reserved.py index 99535c2a7b2..3223b3975db 100644 --- a/lib/ansible/vars/reserved.py +++ b/lib/ansible/vars/reserved.py @@ -70,9 +70,11 @@ def get_reserved_names(include_private=True): def warn_if_reserved(myvars): ''' this function warns if any variable passed conflicts with internally reserved names ''' - reserved = get_reserved_names() - for varname in myvars: - if varname == 'vars': - continue # we add this one internally - if varname in reserved: - display.warning('Found variable using reserved name: %s' % varname) + + varnames = set(myvars) + varnames.discard('vars') # we add this one internally, so safe to ignore + for varname in varnames.intersection(_RESERVED_NAMES): + display.warning('Found variable using reserved name: %s' % varname) + + +_RESERVED_NAMES = frozenset(get_reserved_names())