From d409ec98e3889462e59c85a4b34f9f83ce40bf2c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 18:44:13 -0700 Subject: [PATCH] Run CPython test suite in our CI (#353) --- .github/workflows/ci.yml | 8 ++++++++ CHANGELOG.md | 4 +++- src/test_typing_extensions.py | 4 ++-- src/typing_extensions.py | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dc21e06..1174ce36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,14 @@ jobs: cd src python -m unittest test_typing_extensions.py + - name: Test CPython typing test suite + run: | + # Run the typing test suite from CPython with typing_extensions installed, + # because we monkeypatch typing under some circumstances. + python -c 'import typing_extensions; import test.__main__' test_typing -v + # Test suite fails on PyPy even without typing_extensions + if: !startsWith(matrix.python-version, 'pypy') + linting: name: Lint diff --git a/CHANGELOG.md b/CHANGELOG.md index a545e25b..ce9d3f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ -# Release 4.11.0 (WIP) +# Unreleased +- Fix minor discrepancy between error messages produced by `typing` + and `typing_extensions` on Python 3.10. Patch by Jelle Zijlstra. - When `include_extra=False`, `get_type_hints()` now strips `ReadOnly` from the annotation. # Release 4.10.0 (February 24, 2024) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index d48880ff..8940145e 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -3262,7 +3262,7 @@ def __call__(self, *args: Unpack[Ts]) -> T: ... self.assertEqual(MemoizedFunc.__parameters__, (Ts, T, T2)) self.assertTrue(MemoizedFunc._is_protocol) - things = "arguments" if sys.version_info >= (3, 11) else "parameters" + things = "arguments" if sys.version_info >= (3, 10) else "parameters" # A bug was fixed in 3.11.1 # (https://github.com/python/cpython/commit/74920aa27d0c57443dd7f704d6272cca9c507ab3) @@ -5711,7 +5711,7 @@ class Y(Generic[T], NamedTuple): self.assertIsInstance(a, G) self.assertEqual(a.x, 3) - things = "arguments" if sys.version_info >= (3, 11) else "parameters" + things = "arguments" if sys.version_info >= (3, 10) else "parameters" with self.assertRaisesRegex(TypeError, f'Too many {things}'): G[int, str] diff --git a/src/typing_extensions.py b/src/typing_extensions.py index 4499c616..94218334 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -164,7 +164,8 @@ def _check_generic(cls, parameters, elen=_marker): num_tv_tuples = sum(isinstance(p, TypeVarTuple) for p in parameters) if (num_tv_tuples > 0) and (alen >= elen - num_tv_tuples): return - raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};" + things = "arguments" if sys.version_info >= (3, 10) else "parameters" + raise TypeError(f"Too {'many' if alen > elen else 'few'} {things} for {cls};" f" actual {alen}, expected {elen}")