I will explain it in the following few lines of code..

name = "George"
year = 2021

d = {"name": "Mike", "year": 1919}

match d:
        
        case {"name": name, "year": 1917}:
                print("match 1 found”)
                # I want to remove binding "name" here from partial matching
        
        case {"year": year, "name": "Michael”}:
                print("match 2 found”)
                # I want to remove binding "year" here from partial matching. 
                # Basically removing all name bindings after every 
partial/failed matching 
        
        case _:
                print("match not found!”)
                print(f"{name = }, {year = }”)

### Output ###: 
match not found!
name = 'Mike', year = 1919

But I want :var: 'name' to stay being the global name “George" and :var: 'year' 
being the global year 2021 if an exact matching is not found.

Maybe it is done the way it is for speed optimization (overhead reduction or 
something), but what if I don't care about speed and I care about having no 
un-intentional side-effects? 

Can we do something like the following to solve this issue?
match d, partial_binding=False:
        case … : ...
        case … : ...
with partial_binding=True by default.

Any other idea in how to prevent name binding due to partial matching from 
happening? Any previous discussions on this? 

Thanks, 

Abdulla
_______________________________________________
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/HOFNVZ6KJA6SHCE4NCLPSK27XLDMK7VR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to