dct = {'a': 1, 'b': 2}
dct_1 = {'a': 1}
dct_2 = {'b': 2}
match dct:
case {'b': 2, **dct_1}: print("using {'b': 2, **dct_1}", dct)
outputs,
using {'b': 2, **dct_1} {'a': 1, 'b': 2}
but,
match dct:
case {**dct_1, 'b': 2}: print("using {**dct_1, 'b': 2}", dct)
gives error,
case {**dct_1, 'b': 2}: print("using {**dct_1, 'b': 2}", dct)
^^^
SyntaxError: invalid syntax
and,
match dct:
case {**dct_1, **dct_2}: print("using {**dct_1, **dct_2))}", dct)
gives error,
case {**dct_1, **dct_2}: print("using {**dct_1, **dct_2))}", dct)
^^
SyntaxError: invalid syntax
in the documentation, it is mentioned that this is like a rule.
using **
more than once is not allowed, (although I do not know what could be the reason for it)
plus, using **
is only allowed at the end.
this thing appears to be pretty specific, which one would have to search in the documentation.
that is here,
https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-mapping_pattern
I think so, instead of,
SyntaxError: invalid syntax
there must be a description for it.