mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Add test case for duplicate keyword attributes
This commit is contained in:
parent
640b205517
commit
9375e2b27e
2 changed files with 8 additions and 1 deletions
|
|
@ -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, ...):
|
||||
... ...
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue