on further investigation, I found out that there is some issue with tuple vs list matching using the technique you described.
x = ['a', 'b', 'c', 'd']
y = ('a', 'b', 'c')
match y:
case ['a', *others]:
print(1)
case ('a', *others):
print(2)
gives 1
, which should give 2
one way to make it work is this,
x = ['a', 'b', 'c', 'd']
y = ('a', 'b', 'c')
match y:
case list(['a', *others]):
print(1)
case tuple(('a', *others)):
print(2)
which gives 2
I am still investigating, use cases for these operators to work in match case, as it is not only +
, but even other operators, like *
, -
.
but the main reason is to make the operators work the same way as they do outside of the match case statement for these types.
for example, if one wants to do a exact list match for,
x = [1, 2] * 10000
match x:
case list([1, 2, 1, 2, ...]): # in the current scenario, would have to write it 10000 times, which is not feasible
better would have been,
x = [1, 2] * 10000
match x:
case list([1, 2] * 10000):
but this syntax is invalid currently.