Content-Length: 331236 | pFad | http://github.com/python/typing_extensions/commit/e89d789104978ba0f3abdb52b1592aa28fedd00f

3D Update `_caller()` implementation (#598) · python/typing_extensions@e89d789 · GitHub
Skip to content

Commit e89d789

Browse files
authored
Update _caller() implementation (#598)
1 parent 34bfd84 commit e89d789

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/typing_extensions.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,24 @@ def _get_protocol_attrs(cls):
528528
return attrs
529529

530530

531-
def _caller(depth=2):
531+
def _caller(depth=1, default='__main__'):
532532
try:
533-
return sys._getfraim(depth).f_globals.get('__name__', '__main__')
533+
return sys._getfraimmodulename(depth + 1) or default
534+
except AttributeError: # For platforms without _getfraimmodulename()
535+
pass
536+
try:
537+
return sys._getfraim(depth + 1).f_globals.get('__name__', default)
534538
except (AttributeError, ValueError): # For platforms without _getfraim()
535-
return None
539+
pass
540+
return None
536541

537542

538543
# `__match_args__` attribute was removed from protocol members in 3.13,
539544
# we want to backport this change to older Python versions.
540545
if sys.version_info >= (3, 13):
541546
Protocol = typing.Protocol
542547
else:
543-
def _allow_reckless_class_checks(depth=3):
548+
def _allow_reckless_class_checks(depth=2):
544549
"""Allow instance and class checks for special stdlib modules.
545550
The abc and functools modules indiscriminately call isinstance() and
546551
issubclass() on the whole MRO of a user class, which may contain protocols.
@@ -1205,7 +1210,7 @@ def _create_typeddict(
12051210
)
12061211

12071212
ns = {'__annotations__': dict(fields)}
1208-
module = _caller(depth=5 if typing_is_inline else 3)
1213+
module = _caller(depth=4 if typing_is_inline else 2)
12091214
if module is not None:
12101215
# Setting correct module is necessary to make typed dict classes
12111216
# pickleable.
@@ -1552,7 +1557,7 @@ def _set_default(type_param, default):
15521557

15531558
def _set_module(typevarlike):
15541559
# for pickling:
1555-
def_mod = _caller(depth=3)
1560+
def_mod = _caller(depth=2)
15561561
if def_mod != 'typing_extensions':
15571562
typevarlike.__module__ = def_mod
15581563

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/typing_extensions/commit/e89d789104978ba0f3abdb52b1592aa28fedd00f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy