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) {