diff --git a/lib/ansible/template/safe_eval.py b/lib/ansible/template/safe_eval.py index 8147dc575f..8e06512d12 100644 --- a/lib/ansible/template/safe_eval.py +++ b/lib/ansible/template/safe_eval.py @@ -67,8 +67,8 @@ def safe_eval(expr, locals={}, include_exceptions=False): ) # AST node types were expanded after 2.6 - if not sys.version.startswith('2.6'): - SAFE_NODES.union( + if sys.version_info[:2] >= (2, 7): + SAFE_NODES.update( set( (ast.Set,) ) diff --git a/test/units/template/test_safe_eval.py b/test/units/template/test_safe_eval.py index 610d471443..531244d15a 100644 --- a/test/units/template/test_safe_eval.py +++ b/test/units/template/test_safe_eval.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import sys from collections import defaultdict from ansible.compat.tests import unittest @@ -45,3 +46,6 @@ class TestSafeEval(unittest.TestCase): self.assertEqual(safe_eval('[]', locals=locals_vars), []) self.assertEqual(safe_eval('{}', locals=locals_vars), {}) + @unittest.skipUnless(sys.version_info[:2] >= (2, 7), "Python 2.6 has no set literals") + def test_set_literals(self): + self.assertEqual(safe_eval('{0}'), set([0]))