diff options
author | Steve Dower <steve.dower@python.org> | 2023-01-13 11:31:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 11:31:06 (GMT) |
commit | b5d4347950399800c6703736d716f08761b29245 (patch) | |
tree | bb838154108d6740e062cd5b3d0756fd1a4f2d89 /Lib/collections | |
parent | 94fc7706b7bc3d57cdd6d15bf8e8c4499ae53a69 (diff) | |
download | cpython-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/collections')
-rw-r--r-- | Lib/collections/__init__.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index f07ee14..b5e4d16 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -507,9 +507,12 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non # specified a particular module. if module is None: try: - module = _sys._getframe(1).f_globals.get('__name__', '__main__') - except (AttributeError, ValueError): - pass + module = _sys._getframemodulename(1) or '__main__' + except AttributeError: + try: + module = _sys._getframe(1).f_globals.get('__name__', '__main__') + except (AttributeError, ValueError): + pass if module is not None: result.__module__ = module |