That makes sense. As Guido mentioned, this is similar to reusing a variable in a for-loop. You do it at your own risk. Ok consider me convinced. I will use the following sentence to explain name binding in partial matching:
“Match statements are liable to any or all names bound in any of the patterns used, and your code is incorrect if you aren't prepared for that."

On 14 Feb 2021, at 7:20 PM, Chris Angelico <> wrote:

On Sun, Feb 14, 2021 at 11:26 PM Abdulla Al Kathiri
<> 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.

Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: