From 62cdc6e108007b27cbac09774fa6fbb6963726cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 21:00:40 +0000 Subject: [PATCH 1/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.6 → v0.12.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.6...v0.12.2) - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v5.0.0) - [github.com/python-jsonschema/check-jsonschema: 0.33.0 → 0.33.2](https://github.com/python-jsonschema/check-jsonschema/compare/0.33.0...0.33.2) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7bbfd2ca..5408e91a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.6 + rev: v0.12.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -22,7 +22,7 @@ repos: hooks: - id: sphinx-lint - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.33.0 + rev: 0.33.2 hooks: - id: check-dependabot - id: check-github-workflows From cddbce1a33f4389988c8ce69298928ce9f2e5002 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 21:08:26 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/test_typing_extensions.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index 3ef29474..22798390 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -1211,7 +1211,7 @@ def test_illegal_parameters_do_not_raise_runtime_errors(self): # Type checkers should reject these types, but we do not # raise errors at runtime to maintain maximum flexibility Literal[int] - Literal[Literal[1, 2], Literal[4, 5]] + Literal[1, 2, 4, 5] Literal[3j + 2, ..., ()] Literal[b"foo", "bar"] Literal[{"foo": 3, "bar": 4}] @@ -1283,7 +1283,7 @@ def test_hash(self): def test_args(self): self.assertEqual(Literal[1, 2, 3].__args__, (1, 2, 3)) self.assertEqual(Literal[1, 2, 3, 3].__args__, (1, 2, 3)) - self.assertEqual(Literal[1, Literal[2], Literal[3, 4]].__args__, (1, 2, 3, 4)) + self.assertEqual(Literal[1, 2, 3, 4].__args__, (1, 2, 3, 4)) # Mutable arguments will not be deduplicated self.assertEqual(Literal[[], []].__args__, ([], [])) @@ -1346,9 +1346,9 @@ class Ints(enum.IntEnum): (Literal[1], Literal[Ints.B])) def test_flatten(self): - l1 = Literal[Literal[1], Literal[2], Literal[3]] - l2 = Literal[Literal[1, 2], 3] - l3 = Literal[Literal[1, 2, 3]] + l1 = Literal[1, 2, 3] + l2 = Literal[1, 2, 3] + l3 = Literal[1, 2, 3] for lit in l1, l2, l3: self.assertEqual(lit, Literal[1, 2, 3]) self.assertEqual(lit.__args__, (1, 2, 3)) @@ -1359,12 +1359,7 @@ class Ints(enum.IntEnum): A = 1 B = 2 - literal = Literal[ - Literal[Ints.A], - Literal[Ints.B], - Literal[1], - Literal[2], - ] + literal = Literal[Ints.A, Ints.B, 1, 2] self.assertEqual(literal.__args__, (Ints.A, Ints.B, 1, 2)) def test_caching_of_Literal_respects_type(self): From 94a048aa2e57728ba2af171e994722521f5e410a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 8 Jul 2025 15:02:15 +0100 Subject: [PATCH 3/5] Revert bad Ruff autofixes --- src/test_typing_extensions.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index 22798390..3ef29474 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -1211,7 +1211,7 @@ def test_illegal_parameters_do_not_raise_runtime_errors(self): # Type checkers should reject these types, but we do not # raise errors at runtime to maintain maximum flexibility Literal[int] - Literal[1, 2, 4, 5] + Literal[Literal[1, 2], Literal[4, 5]] Literal[3j + 2, ..., ()] Literal[b"foo", "bar"] Literal[{"foo": 3, "bar": 4}] @@ -1283,7 +1283,7 @@ def test_hash(self): def test_args(self): self.assertEqual(Literal[1, 2, 3].__args__, (1, 2, 3)) self.assertEqual(Literal[1, 2, 3, 3].__args__, (1, 2, 3)) - self.assertEqual(Literal[1, 2, 3, 4].__args__, (1, 2, 3, 4)) + self.assertEqual(Literal[1, Literal[2], Literal[3, 4]].__args__, (1, 2, 3, 4)) # Mutable arguments will not be deduplicated self.assertEqual(Literal[[], []].__args__, ([], [])) @@ -1346,9 +1346,9 @@ class Ints(enum.IntEnum): (Literal[1], Literal[Ints.B])) def test_flatten(self): - l1 = Literal[1, 2, 3] - l2 = Literal[1, 2, 3] - l3 = Literal[1, 2, 3] + l1 = Literal[Literal[1], Literal[2], Literal[3]] + l2 = Literal[Literal[1, 2], 3] + l3 = Literal[Literal[1, 2, 3]] for lit in l1, l2, l3: self.assertEqual(lit, Literal[1, 2, 3]) self.assertEqual(lit.__args__, (1, 2, 3)) @@ -1359,7 +1359,12 @@ class Ints(enum.IntEnum): A = 1 B = 2 - literal = Literal[Ints.A, Ints.B, 1, 2] + literal = Literal[ + Literal[Ints.A], + Literal[Ints.B], + Literal[1], + Literal[2], + ] self.assertEqual(literal.__args__, (Ints.A, Ints.B, 1, 2)) def test_caching_of_Literal_respects_type(self): From 9e73f1122c6615b1b7d6cefb2e4f455b61f23032 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 8 Jul 2025 15:03:19 +0100 Subject: [PATCH 4/5] rename test and rewrite comment --- src/test_typing_extensions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index 3ef29474..fa4ce5ba 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -1207,9 +1207,8 @@ class My(enum.Enum): self.assertEqual(Literal[My.A].__args__, (My.A,)) - def test_illegal_parameters_do_not_raise_runtime_errors(self): - # Type checkers should reject these types, but we do not - # raise errors at runtime to maintain maximum flexibility + def test_nested_literals_are_allowed(self): + # These are explicitly allowed by the typing spec Literal[int] Literal[Literal[1, 2], Literal[4, 5]] Literal[3j + 2, ..., ()] From e4702d6b30e62ea9255c3946cf54d6bce14d2d88 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 9 Jul 2025 15:25:51 +0100 Subject: [PATCH 5/5] fix --- src/test_typing_extensions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index fa4ce5ba..cb3b462b 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -1207,12 +1207,15 @@ class My(enum.Enum): self.assertEqual(Literal[My.A].__args__, (My.A,)) - def test_nested_literals_are_allowed(self): + def test_strange_parameters_are_allowed(self): # These are explicitly allowed by the typing spec - Literal[int] Literal[Literal[1, 2], Literal[4, 5]] - Literal[3j + 2, ..., ()] Literal[b"foo", "bar"] + + # Type checkers should reject these types, but we do not + # raise errors at runtime to maintain maximum flexibility + Literal[int] + Literal[3j + 2, ..., ()] Literal[{"foo": 3, "bar": 4}] Literal[T]