]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141510 Document and test frozendict class matching behaviour (#150799)
authorda-woods <dw-git@d-woods.co.uk>
Thu, 18 Jun 2026 12:53:09 +0000 (13:53 +0100)
committerGitHub <noreply@github.com>
Thu, 18 Jun 2026 12:53:09 +0000 (14:53 +0200)
Frozendict has `_Py_TPFLAGS_MATCH_SELF` set so works correctly
with the single-arg class matching. However it isn't documented
in the list of classes this works with and it isn't tested.

The test is some way below the other similar tests but anything
else would need a large renumbering.

Doc/reference/compound_stmts.rst
Lib/test/test_patma.py

index 6710c0acf77e3507a0fffa940295e651597858a8..b3168bb85b4765d28e162ee2c91e924ddaf58de7 100644 (file)
@@ -1172,6 +1172,7 @@ subject value:
    * :class:`bytes`
    * :class:`dict`
    * :class:`float`
+   * :class:`frozendict`
    * :class:`frozenset`
    * :class:`int`
    * :class:`list`
index 29cce4ee6d271ff5711a288537d23c4e26821516..e3aaea84ea7ce84d7e8482317c2f8a7e1f9d3a72 100644 (file)
@@ -2852,6 +2852,15 @@ class TestPatma(unittest.TestCase):
         self.assertEqual(x, 0)
         self.assertEqual(y, 1)
 
+    def test_patma_frozendict_class_self(self):
+        x = frozendict()
+        match x:
+            case frozendict(z):
+                y = 0
+        self.assertEqual(x, frozendict())
+        self.assertEqual(y, 0)
+        self.assertIs(z, x)
+
     def test_patma_runtime_checkable_protocol(self):
         # Runtime-checkable protocol
         from typing import Protocol, runtime_checkable