aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/typing-extensions/py3/typing_extensions.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-06-22 14:14:29 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-06-22 14:25:20 +0300
commitb41b2afa94a8d2a34ca61d8add00730c1f09d110 (patch)
treedadc24f0e9255c1750268a5d5188a991e27876dc /contrib/python/typing-extensions/py3/typing_extensions.py
parentec6419ce54cc774514785609c6fa060f73af4bd1 (diff)
downloadydb-b41b2afa94a8d2a34ca61d8add00730c1f09d110.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/typing-extensions/py3/typing_extensions.py')
-rw-r--r--contrib/python/typing-extensions/py3/typing_extensions.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/contrib/python/typing-extensions/py3/typing_extensions.py b/contrib/python/typing-extensions/py3/typing_extensions.py
index 46084fa56f..dec429ca87 100644
--- a/contrib/python/typing-extensions/py3/typing_extensions.py
+++ b/contrib/python/typing-extensions/py3/typing_extensions.py
@@ -2954,13 +2954,20 @@ if not _PEP_696_IMPLEMENTED:
def _has_generic_or_protocol_as_origin() -> bool:
try:
frame = sys._getframe(2)
- # not all platforms have sys._getframe()
- except AttributeError:
+ # - Catch AttributeError: not all Python implementations have sys._getframe()
+ # - Catch ValueError: maybe we're called from an unexpected module
+ # and the call stack isn't deep enough
+ except (AttributeError, ValueError):
return False # err on the side of leniency
else:
- return frame.f_locals.get("origin") in (
- typing.Generic, Protocol, typing.Protocol
- )
+ # If we somehow get invoked from outside typing.py,
+ # also err on the side of leniency
+ if frame.f_globals.get("__name__") != "typing":
+ return False
+ origin = frame.f_locals.get("origin")
+ # Cannot use "in" because origin may be an object with a buggy __eq__ that
+ # throws an error.
+ return origin is typing.Generic or origin is Protocol or origin is typing.Protocol
_TYPEVARTUPLE_TYPES = {TypeVarTuple, getattr(typing, "TypeVarTuple", None)}