Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9cb50cb

Browse filesBrowse files
committed
Restore compatibility with PyPy <3.9
1 parent bc9bc06 commit 9cb50cb
Copy full SHA for 9cb50cb

File tree

Expand file treeCollapse file tree

3 files changed

+32
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-3
lines changed

‎.github/workflows/ci.yml

Copy file name to clipboardExpand all lines: .github/workflows/ci.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ jobs:
5353
- "3.11"
5454
- "3.11.0"
5555
- "3.12"
56+
- "pypy3.7"
57+
- "pypy3.8"
5658
- "pypy3.9"
5759
- "pypy3.10"
5860

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Release 4.7.1 (???)
2+
3+
- Fix `TypedDict`, `NamedTuple` and `is_protocol` tests on PyPy-3.7 and
4+
PyPy-3.8. Patch by Alex Waygood.
5+
16
# Release 4.7.0 (June 28, 2023)
27

38
- This is expected to be the last feature release supporting Python 3.7,

‎src/typing_extensions.py

Copy file name to clipboardExpand all lines: src/typing_extensions.py
+25-3Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
'no_type_check_decorator',
129129
]
130130

131+
_OLD_PYPY_VERSION = sys.implementation.name == "pypy" and sys.version_info < (3, 9)
132+
131133
# for backward compatibility
132134
PEP_560 = True
133135
GenericMeta = type
@@ -1143,7 +1145,18 @@ class Point2D(TypedDict):
11431145
return td
11441146

11451147
_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {})
1146-
TypedDict.__mro_entries__ = lambda bases: (_TypedDict,)
1148+
1149+
if _OLD_PYPY_VERSION:
1150+
class _TypedDictType:
1151+
__call__ = staticmethod(TypedDict)
1152+
1153+
def __mro_entries__(self, bases):
1154+
return (_TypedDict,)
1155+
1156+
TypedDict = _TypedDictType()
1157+
functools.update_wrapper(TypedDict, TypedDict.__call__)
1158+
else:
1159+
TypedDict.__mro_entries__ = lambda bases: (_TypedDict,)
11471160

11481161
if hasattr(typing, "_TypedDictMeta"):
11491162
_TYPEDDICT_TYPES = (typing._TypedDictMeta, _TypedDictMeta)
@@ -2710,7 +2723,15 @@ def _namedtuple_mro_entries(bases):
27102723
assert NamedTuple in bases
27112724
return (_NamedTuple,)
27122725

2713-
NamedTuple.__mro_entries__ = _namedtuple_mro_entries
2726+
if _OLD_PYPY_VERSION:
2727+
class _NamedTupleType:
2728+
__call__ = staticmethod(NamedTuple)
2729+
__mro_entries__ = staticmethod(_namedtuple_mro_entries)
2730+
2731+
NamedTuple = _NamedTupleType()
2732+
functools.update_wrapper(NamedTuple, NamedTuple.__call__)
2733+
else:
2734+
NamedTuple.__mro_entries__ = _namedtuple_mro_entries
27142735

27152736

27162737
if hasattr(collections.abc, "Buffer"):
@@ -2986,7 +3007,8 @@ def is_protocol(__tp: type) -> bool:
29863007
return (
29873008
isinstance(__tp, type)
29883009
and getattr(__tp, '_is_protocol', False)
2989-
and __tp != Protocol
3010+
and __tp is not Protocol
3011+
and __tp is not getattr(typing, "Protocol", object())
29903012
)
29913013

29923014
def get_protocol_members(__tp: type) -> typing.FrozenSet[str]:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.