summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2023-01-13 11:31:06 (GMT)
committerGitHub <noreply@github.com>2023-01-13 11:31:06 (GMT)
commitb5d4347950399800c6703736d716f08761b29245 (patch)
treebb838154108d6740e062cd5b3d0756fd1a4f2d89 /Lib/enum.py
parent94fc7706b7bc3d57cdd6d15bf8e8c4499ae53a69 (diff)
downloadcpython-b5d4347950399800c6703736d716f08761b29245.zip
cpython-b5d4347950399800c6703736d716f08761b29245.tar.gz
cpython-b5d4347950399800c6703736d716f08761b29245.tar.bz2
gh-86682: Adds sys._getframemodulename as an alternative to using _getframe (GH-99520)
Also updates calls in collections, doctest, enum, and typing modules to use _getframemodulename first when available.
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 21f6388..4658393 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -862,13 +862,15 @@ class EnumType(type):
member_name, member_value = item
classdict[member_name] = member_value
- # TODO: replace the frame hack if a blessed way to know the calling
- # module is ever developed
if module is None:
try:
- module = sys._getframe(2).f_globals['__name__']
- except (AttributeError, ValueError, KeyError):
- pass
+ module = sys._getframemodulename(2)
+ except AttributeError:
+ # Fall back on _getframe if _getframemodulename is missing
+ try:
+ module = sys._getframe(2).f_globals['__name__']
+ except (AttributeError, ValueError, KeyError):
+ pass
if module is None:
_make_class_unpicklable(classdict)
else: