[ snip ]
To address 2), bind '_' when it's used as a name in a pattern.
This adds an extra reference and an extra store. That by itself
seems harmless.
This is not always just a store. for patterns like `[a, *_, b]` vs `[a, *ignore_me, b]`, the current semantics mean that the matching process has to make 2 calls to `__getitem__` on the match subject. The second case (which would be equivalent to "remove special meaning on _") will have to actually create a new list and copy most of the original one which can be arbitrarily long, so this turns an O(1) operation into O(n).
The existing implementation has optimizations here. If that's
important, we could achieve the same result with a little dataflow
analysis to optimize away the dead store. We could even
special-case optimizing away dead stores only to '_' and only
in match/case statements and all would be forgiven.
This might work, although it's quite different to what python does in general (are you supposed to see the value of `_` in a debugger? or in `locals()`? )
Cheers,
D.