From 9375e2b27e27ce6ce5ca28128b0403eb894d3553 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 21 Dec 2025 23:28:26 +0100 Subject: [PATCH] Add test case for duplicate keyword attributes --- Lib/test/test_syntax.py | 6 ++++++ Python/ceval.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 93f0b98de71..f245db287be 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -2345,6 +2345,12 @@ Invalid pattern matching constructs: Traceback (most recent call last): SyntaxError: positional patterns follow keyword patterns + >>> match ...: + ... case Foo(y=1, x=2, y=3): + ... ... + Traceback (most recent call last): + SyntaxError: attribute name repeated in class pattern: y + >>> match ...: ... case C(a=b, c, d=e, f, g=h, i, j=k, ...): ... ... diff --git a/Python/ceval.c b/Python/ceval.c index 51f9fcde6d0..2623eff5a33 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -887,7 +887,8 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, // So far so good: PyObject *seen = NULL; // Only check for duplicates if there is at least one positional attribute - // and two or more attributes in total. + // and two or more attributes in total. Duplicate keyword attributes are + // detected during the compile stage and raise a SyntaxError. if (nargs > 0 && nattrs > 1) { seen = PySet_New(NULL); if (seen == NULL) {