[Python-ideas] PEP Idea: Matching Exceptions with 3.10's Structural Pattern Matching Syntax

2022-01-03 Thread elvis kahoro
bout is: match (named_tuple_object.*missing_attribute*, a_random_string): case *AttributeError*, "Catching an attribute error": print("Catches as attribute error") case *err:= AttributeError*, "Assigns an attribute error as err": print(f"This is the capt

[Python-ideas] Re: PEP Idea: Matching Exceptions with 3.10's Structural Pattern Matching Syntax

2022-01-03 Thread elvis kahoro
kind of syntax? Maybe the author could explicitly distinguish that an exception might be raised by using *with Exception *like so: match *this_raises_an_exception*, *this_raises_another_exception** with Exception:* On Mon, Jan 3, 2022 at 7:25 PM Steven D'Aprano wrote: > Hi Elvis, > &g

[Python-ideas] Re: PEP Idea: Matching Exceptions with 3.10's Structural Pattern Matching Syntax

2022-01-03 Thread elvis kahoro
Thanks for the feedback everyone. I've only encountered the use case once, like you've mentioned it's probably not worth the effort given that it's such a small problem space. Thanks again! On Tue, Jan 4, 2022, 00:18 Steven D'Aprano wrote: > On Mon, Jan 03, 202