summaryrefslogtreecommitdiffstats
path: root/Lib/typing.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/typing.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/typing.py')
-rw-r--r--Lib/typing.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 8bc38f9..4675af1 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1940,10 +1940,14 @@ def _no_init_or_replace_init(self, *args, **kwargs):
def _caller(depth=1, default='__main__'):
try:
+ return sys._getframemodulename(depth + 1) or default
+ except AttributeError: # For platforms without _getframemodulename()
+ pass
+ try:
return sys._getframe(depth + 1).f_globals.get('__name__', default)
except (AttributeError, ValueError): # For platforms without _getframe()
- return None
-
+ pass
+ return None
def _allow_reckless_class_checks(depth=3):
"""Allow instance and class checks for special stdlib modules.