[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, 2022 at 11:31:30PM -0500, elvis kah

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

2022-01-03 Thread Steven D'Aprano
On Mon, Jan 03, 2022 at 11:31:30PM -0500, elvis kahoro wrote: > I was hoping there could be some syntax to extend pattern matching to > handle exceptions such that we could handle patterns with multiple types of > exceptions like so: > > match *this_raises_an_exception*, *this_raises_another_exce

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

2022-01-03 Thread Chris Angelico
On Tue, Jan 4, 2022 at 3:32 PM elvis kahoro wrote: >> >> Reading between the lines, I *think* that you want the match statement >> to catch the exception that you get when the attribute lookup fails, am >> I right? > > Yes! > > I was hoping there could be some syntax to extend pattern matching to

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

2022-01-03 Thread elvis kahoro
> > Reading between the lines, I *think* that you want the match statement > to catch the exception that you get when the attribute lookup fails, am > I right? Yes! I was hoping there could be some syntax to extend pattern matching to handle exceptions such that we could handle patterns with mult

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

2022-01-03 Thread Stephen J. Turnbull
Steven D'Aprano writes: > I propose: > > match expression: > except exceptions: > block > # regular cases follow after the except block I probably would rarely use this syntax (preferring the explicit temporary, and possibly encapsulating the exception handl

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

2022-01-03 Thread Steven D'Aprano
Hi Elvis, On Sat, Jan 01, 2022 at 12:59:32AM -0500, elvis kahoro wrote: > The functionality that I'm thinking about is: > > match (named_tuple_object.*missing_attribute*, a_random_string): > case *AttributeError*, "Catching an attribute error": > print("Catches as attribute error")

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

2022-01-03 Thread elvis kahoro
Dear The PEP Community, Happy New Year! I'm assuming there's been discussions on this already! I checked the current PEP list and issue tracker, but to no avail. *Can someone point me to wherever it has or is taking place?* The functionality that I'm thinking about is: match (named_tuple_objec