On Sun, Feb 14, 2021 at 11:26 PM Abdulla Al Kathiri email@example.com wrote:
My idea was that in the case of partial matching or full matching without passing the guard, the binding names has some sort of self destruction and return to the previous state. Using different variable names would resolve the issue and if I want to modify the global variables, I could choose to do so in the case block after the case succeeded. At least, this way, it would be more explicit, conveying the person intention (or forgetting if the original global value was later needed). I saw many people online talking about this the last couple of days so I thought I would bring it up here. Any other syntax variant could be used to achieve the same thing.
It's not about syntax. Python doesn't have an idea of "self destruction and return to the previous state". The nearest equivalent is a very special case at the end of an exception handler, where after "except Exception as e:" you'll get an implicit "e = None; del e" to prevent a refloop. That's not a return to the previous state, that's a conscious clearing of one reference.
If this "unwinding" were desired, the best way would be to simply make it a permanent part of the match semantics - no syntax for selecting which behaviour you want. There's no backward compatibility to be maintained (yet). But that would be inconsistent with the rest of Python, where things happen step by step, and if something breaks, everything prior to it has happened.