From 1fd06f1eca80dcbf3a916133919482a8327f3da4 Mon Sep 17 00:00:00 2001 From: Rémi Lapeyre Date: Thu, 24 Jan 2019 20:43:13 +0100 Subject: bpo-35717: Fix KeyError exception raised when using enums and compile (GH-11523) https://bugs.python.org/issue17467 --- Lib/test/test_enum.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Lib/test/test_enum.py') diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 572e8733f45..99fc85074b7 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1858,6 +1858,15 @@ class TestEnum(unittest.TestCase): REVERT_ALL = "REVERT_ALL" RETRY = "RETRY" + def test_empty_globals(self): + # bpo-35717: sys._getframe(2).f_globals['__name__'] fails with KeyError + # when using compile and exec because f_globals is empty + code = "from enum import Enum; Enum('Animal', 'ANT BEE CAT DOG')" + code = compile(code, "", "exec") + global_ns = {} + local_ls = {} + exec(code, global_ns, local_ls) + class TestOrder(unittest.TestCase): -- cgit v1.2.3