mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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.
This commit is contained in:
parent
94fc7706b7
commit
b5d4347950
13 changed files with 200 additions and 14 deletions
12
Lib/enum.py
12
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue