On Sun, Feb 14, 2021 at 11:26 PM Abdulla Al Kathiri <alkathiri.abdu...@gmail.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. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5K65WY7B6O7EO5ZKWZZCS3OYV2HCIBQJ/ Code of Conduct: http://python.org/psf/codeofconduct/