From ba0dfc87f7e0be06cbb5e71478d7e0d31f4ddc98 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:33:51 -0700 Subject: [PATCH 1/8] Run CPython test suite in our CI --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dc21e06..a36285e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,9 @@ jobs: # accidentally pick up typing_extensions as installed by a dependency cd src python -m unittest test_typing_extensions.py + # 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 linting: name: Lint From ec47742f2b41ebce54d6ff316fa25d9ad9156ea6 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:35:37 -0700 Subject: [PATCH 2/8] tell me what went wrong --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a36285e1..691906fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: python -m unittest test_typing_extensions.py # 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 + python -c 'import typing_extensions; import test.__main__' test_typing -v linting: name: Lint From dbc595036bb2564e6c19200b4b22b80744fc52e6 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:36:41 -0700 Subject: [PATCH 3/8] fix 3.10 --- src/typing_extensions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/typing_extensions.py b/src/typing_extensions.py index f3132ea4..7b0f7e39 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -164,7 +164,11 @@ 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};" + if (3, 10) <= sys.version_info < (3, 11): + word = "arguments" + else: + word = "parameters" + raise TypeError(f"Too {'many' if alen > elen else 'few'} {word} for {cls};" f" actual {alen}, expected {elen}") From 6641a5a3a13a7e44bc001eb95619e67ef2efcba2 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:39:56 -0700 Subject: [PATCH 4/8] fix our own tests --- src/test_typing_extensions.py | 4 ++-- src/typing_extensions.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index 79c1b881..e7871aec 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) @@ -5697,7 +5697,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 7b0f7e39..900c90a3 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -164,7 +164,7 @@ 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 - if (3, 10) <= sys.version_info < (3, 11): + if sys.version_info >= (3, 10): word = "arguments" else: word = "parameters" From e735af78d39701011ac2f57b9574928d7afe1776 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:44:22 -0700 Subject: [PATCH 5/8] does it work on pypy without typing_extensions? --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 691906fc..bf05fc7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,9 +73,12 @@ jobs: # accidentally pick up typing_extensions as installed by a dependency 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 + python -c 'import test.__main__' test_typing -v linting: name: Lint From f519c45b6b4ece894596a8094213f9804e1841a5 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:46:35 -0700 Subject: [PATCH 6/8] Sorry PyPy --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf05fc7d..1174ce36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,9 @@ jobs: run: | # Run the typing test suite from CPython with typing_extensions installed, # because we monkeypatch typing under some circumstances. - python -c 'import test.__main__' test_typing -v + 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 From eacbf42ea5252096596ec569a874ba9bc8f74564 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:48:01 -0700 Subject: [PATCH 7/8] Guess it can go into the changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fc328d..37b9a39c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# Unreleased + +- Fix minor discrepancy between error messages produced by `typing` + and `typing_extensions` on Python 3.10. Patch by Jelle Zijlstra. + # Release 4.10.0 (February 24, 2024) This feature release adds support for PEP 728 (TypedDict with extra From 2b4dc3a0d343b320a063f4da76cbff130206eba7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 10 Mar 2024 17:51:05 -0700 Subject: [PATCH 8/8] Update src/typing_extensions.py --- src/typing_extensions.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/typing_extensions.py b/src/typing_extensions.py index 5b5ce97d..94218334 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -164,11 +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 - if sys.version_info >= (3, 10): - word = "arguments" - else: - word = "parameters" - raise TypeError(f"Too {'many' if alen > elen else 'few'} {word} 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}")