Commit 1fd06f1e authored by Rémi Lapeyre's avatar Rémi Lapeyre Committed by Miss Islington (bot)

bpo-35717: Fix KeyError exception raised when using enums and compile (GH-11523)



https://bugs.python.org/issue17467
parent 5c8f5376
......@@ -419,7 +419,7 @@ class EnumMeta(type):
if module is None:
try:
module = sys._getframe(2).f_globals['__name__']
except (AttributeError, ValueError) as exc:
except (AttributeError, ValueError, KeyError) as exc:
pass
if module is None:
_make_class_unpicklable(enum_class)
......
......@@ -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, "<string>", "exec")
global_ns = {}
local_ls = {}
exec(code, global_ns, local_ls)
class TestOrder(unittest.TestCase):
......
......@@ -906,6 +906,7 @@ Glenn Langford
Andrew Langmead
Wolfgang Langner
Detlef Lannert
Rémi Lapeyre
Soren Larsen
Amos Latteier
Piers Lauder
......
Fix KeyError exception raised when using enums and compile. Patch
contributed by Rémi Lapeyre.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment