Skip to content

Commit

Permalink
downgrade typing_extensions for 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur-ob committed Feb 28, 2025
1 parent c5777ee commit a046d97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
45 changes: 13 additions & 32 deletions metaflow/_vendor/v3_7/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,21 +953,6 @@ def __round__(self, ndigits: int = 0) -> T_co:
pass


def _ensure_subclassable(mro_entries):
def inner(func):
if sys.implementation.name == "pypy" and sys.version_info < (3, 9):
cls_dict = {
"__call__": staticmethod(func),
"__mro_entries__": staticmethod(mro_entries)
}
t = type(func.__name__, (), cls_dict)
return functools.update_wrapper(t(), func)
else:
func.__mro_entries__ = mro_entries
return func
return inner


if sys.version_info >= (3, 13):
# The standard library TypedDict in Python 3.8 does not store runtime information
# about which (if any) keys are optional. See https://bugs.python.org/issue38834
Expand Down Expand Up @@ -1074,9 +1059,6 @@ def __subclasscheck__(cls, other):

__instancecheck__ = __subclasscheck__

_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {})

@_ensure_subclassable(lambda bases: (_TypedDict,))
def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs):
"""A simple typed namespace. At runtime it is equivalent to a plain dict.
Expand Down Expand Up @@ -1160,6 +1142,9 @@ class Point2D(TypedDict):
td.__orig_bases__ = (TypedDict,)
return td

_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {})
TypedDict.__mro_entries__ = lambda bases: (_TypedDict,)

if hasattr(typing, "_TypedDictMeta"):
_TYPEDDICT_TYPES = (typing._TypedDictMeta, _TypedDictMeta)
else:
Expand Down Expand Up @@ -2648,13 +2633,6 @@ def __new__(cls, typename, bases, ns):
nm_tpl.__init_subclass__()
return nm_tpl

_NamedTuple = type.__new__(_NamedTupleMeta, 'NamedTuple', (), {})

def _namedtuple_mro_entries(bases):
assert NamedTuple in bases
return (_NamedTuple,)

@_ensure_subclassable(_namedtuple_mro_entries)
def NamedTuple(__typename, __fields=_marker, **kwargs):
"""Typed version of namedtuple.
Expand Down Expand Up @@ -2720,15 +2698,19 @@ class Employee(NamedTuple):
nt.__orig_bases__ = (NamedTuple,)
return nt

_NamedTuple = type.__new__(_NamedTupleMeta, 'NamedTuple', (), {})

# On 3.8+, alter the signature so that it matches typing.NamedTuple.
# The signature of typing.NamedTuple on >=3.8 is invalid syntax in Python 3.7,
# so just leave the signature as it is on 3.7.
if sys.version_info >= (3, 8):
_new_signature = '(typename, fields=None, /, **kwargs)'
if isinstance(NamedTuple, _types.FunctionType):
NamedTuple.__text_signature__ = _new_signature
else:
NamedTuple.__call__.__text_signature__ = _new_signature
NamedTuple.__text_signature__ = '(typename, fields=None, /, **kwargs)'

def _namedtuple_mro_entries(bases):
assert NamedTuple in bases
return (_NamedTuple,)

NamedTuple.__mro_entries__ = _namedtuple_mro_entries


if hasattr(collections.abc, "Buffer"):
Expand Down Expand Up @@ -3004,8 +2986,7 @@ def is_protocol(__tp: type) -> bool:
return (
isinstance(__tp, type)
and getattr(__tp, '_is_protocol', False)
and __tp is not Protocol
and __tp is not getattr(typing, "Protocol", object())
and __tp != Protocol
)

def get_protocol_members(__tp: type) -> typing.FrozenSet[str]:
Expand Down
2 changes: 1 addition & 1 deletion metaflow/_vendor/vendor_v3_7.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
typeguard==4.1.2
typing_extensions==4.7.1
typing_extensions==4.7.0

0 comments on commit a046d97

Please sign in to comment.