Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fd06f1

Browse filesBrowse files
Rémi Lapeyremiss-islington
Rémi Lapeyre
authored andcommitted
bpo-35717: Fix KeyError exception raised when using enums and compile (GH-11523)
https://bugs.python.org/issue17467
1 parent 5c8f537 commit 1fd06f1
Copy full SHA for 1fd06f1

File tree

Expand file treeCollapse file tree

4 files changed

+13
-1
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+13
-1
lines changed

‎Lib/enum.py

Copy file name to clipboardExpand all lines: Lib/enum.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s
419419
if module is None:
420420
try:
421421
module = sys._getframe(2).f_globals['__name__']
422-
except (AttributeError, ValueError) as exc:
422+
except (AttributeError, ValueError, KeyError) as exc:
423423
pass
424424
if module is None:
425425
_make_class_unpicklable(enum_class)

‎Lib/test/test_enum.py

Copy file name to clipboardExpand all lines: Lib/test/test_enum.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,15 @@ class Decision2(MyEnum):
18581858
REVERT_ALL = "REVERT_ALL"
18591859
RETRY = "RETRY"
18601860

1861+
def test_empty_globals(self):
1862+
# bpo-35717: sys._getframe(2).f_globals['__name__'] fails with KeyError
1863+
# when using compile and exec because f_globals is empty
1864+
code = "from enum import Enum; Enum('Animal', 'ANT BEE CAT DOG')"
1865+
code = compile(code, "<string>", "exec")
1866+
global_ns = {}
1867+
local_ls = {}
1868+
exec(code, global_ns, local_ls)
1869+
18611870

18621871
class TestOrder(unittest.TestCase):
18631872

‎Misc/ACKS

Copy file name to clipboardExpand all lines: Misc/ACKS
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ Glenn Langford
906906
Andrew Langmead
907907
Wolfgang Langner
908908
Detlef Lannert
909+
Rémi Lapeyre
909910
Soren Larsen
910911
Amos Latteier
911912
Piers Lauder
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix KeyError exception raised when using enums and compile. Patch
2+
contributed by Rémi Lapeyre.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.