[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Rob Cliffe via Python-Dev
On 12/07/2020 02:04, Guido van Rossum wrote: On Sat, Jul 11, 2020 at 5:58 PM Chris Angelico > wrote: Hang on. Matching happens before assignment, so this should use the previous value of x for the matching. At least, that's my understanding. If you do

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread MRAB
On 2020-07-12 01:32, Chris Angelico wrote: On Sun, Jul 12, 2020 at 10:30 AM Greg Ewing wrote: Just had another thought about marking assignment targets. The PEP currently forbids repeating bound names in a pattern to avoid raising expectations that case Point(x, x): would match only

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Chris Angelico
On Sun, Jul 12, 2020 at 11:04 AM Guido van Rossum wrote: > > On Sat, Jul 11, 2020 at 5:58 PM Chris Angelico wrote: >> >> On Sun, Jul 12, 2020 at 10:30 AM Greg Ewing >> wrote: >> > >> > Just had another thought about marking assignment targets. >> > >> > The PEP currently forbids repeating

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
On 07/11/2020 10:29 AM, Jim J. Jewett wrote: To me, "else:" has a slightly different meaning than "case _:" case _:  essentially a default, ensuring that the match logic is complete. else:  OK, the subject of this match failed, here is our fallback logic. Is there anywhere

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Guido van Rossum
On Sat, Jul 11, 2020 at 5:58 PM Chris Angelico wrote: > On Sun, Jul 12, 2020 at 10:30 AM Greg Ewing > wrote: > > > > Just had another thought about marking assignment targets. > > > > The PEP currently forbids repeating bound names in a pattern > > to avoid raising expectations that > > > >

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Guido van Rossum
On Sat, Jul 11, 2020 at 5:28 PM Greg Ewing wrote: > Just had another thought about marking assignment targets. > > The PEP currently forbids repeating bound names in a pattern > to avoid raising expectations that > > case Point(x, x): > > would match only if the two arguments were equal. >

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Chris Angelico
On Sun, Jul 12, 2020 at 10:30 AM Greg Ewing wrote: > > Just had another thought about marking assignment targets. > > The PEP currently forbids repeating bound names in a pattern > to avoid raising expectations that > > case Point(x, x): > > would match only if the two arguments were equal.

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
On 12/07/20 7:13 am, Eric Nieuwland wrote: match poly: p0 = Point(x0, y0) p1 = Point(x1, y1) p2 = Point(x2, y2) case Polygon(p0, p1, p2): … Interesting idea, but what happens if you *don't* need any setup?

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
On 12/07/20 7:03 am, Federico Salerno wrote: On 11/07/2020 12:49, Greg Ewing wrote:    switch (x) {    case 1:   ...    case 2:   ...    default:   ...    } > I think that last one would be perceived as ok if it weren't for the brackets: everyone naturally indents any set of

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
Just had another thought about marking assignment targets. The PEP currently forbids repeating bound names in a pattern to avoid raising expectations that case Point(x, x): would match only if the two arguments were equal. But if assignment targets were marked, we could write this as

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
On 11/07/20 11:20 pm, Paul Sokolovsky wrote: On Sat, 11 Jul 2020 22:49:09 +1200 Greg Ewing wrote: or like this: switch (x) { case 1: ... case 2: ... default: ... } Oh really, you never saw that? Well, they say that any programmer should

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Guido van Rossum
On Sat, Jul 11, 2020 at 2:45 PM Ethan Furman wrote: > On 07/11/2020 10:29 AM, Jim J. Jewett wrote: > > To me, "else:" has a slightly different meaning than "case _:" > > > > case _: essentially a default, ensuring that the match logic > is complete. > > > > else: OK, the subject

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Ethan Furman
On 07/11/2020 10:29 AM, Jim J. Jewett wrote: To me, "else:" has a slightly different meaning than "case _:" case _: essentially a default, ensuring that the match logic is complete. else: OK, the subject of this match failed, here is our fallback logic. Whether this

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread MRAB
On 2020-07-11 20:56, Steve Holden wrote: Given that case will be a keyword, what's the case (pun unintentional) for indenting the case clauses? What's wrong with 'case' and 'else' both indented the same as match? Without the keyword there'd be a case for indenting, but with it I don't see the

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Eric Nieuwland
On 11 Jul 2020, at 21:03, Eric Nieuwland wrote: > What I meant to say is that as I read the current PEP text there would be a > confusing difference between > > match poly: > case Polygon(Point(x0, y0), Point(x1, y1), Point(x2, y2)): > ... > > and >

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Eric Nieuwland
> On 10 Jul 2020, at 18:28, Jim Baker wrote: > > On Fri, Jul 10, 2020, 9:16 AM Eric Nieuwland wrote: > >> On 10 Jul 2020, at 01:51, Jim Baker wrote: >> ... >> Explicit namespacing (if a constant) or using a guard (if a variable) seems >> to be the right solution, as Ethan demonstrated

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Steve Holden
Given that case will be a keyword, what's the case (pun unintentional) for indenting the case clauses? What's wrong with 'case' and 'else' both indented the same as match? Without the keyword there'd be a case for indenting, but with it I don't see the necessity. Kind regards, Steve On Fri, Jul

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Federico Salerno
On 11/07/2020 00:57, Paul Sokolovsky wrote: The PEP itself in "rejected" ideas makes an argument against it: indented stuff after a line ending with ":" must be a *statement*. It would be totally nuts for that to be something else, e.g. an expression: Good point. That of course leads us to

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Glenn Linderman
On 7/11/2020 10:36 AM, Jim J. Jewett wrote: Glenn Linderman wrote: On 7/10/2020 3:15 AM, Gustavo Carneiro wrote: ... Therefore, I posit that the style of try...except indentation only works where the number of cases is small. But for the case of pattern matching, I expect the number of cases

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Jim J. Jewett
Glenn Linderman wrote: > On 7/10/2020 3:15 AM, Gustavo Carneiro wrote: ... > > Therefore, I posit that the style of try...except indentation only > > works where the number of cases is small. > > But for the case of pattern matching, I expect the number of cases to > > be matched to be a lot

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Jim J. Jewett
To me, "else:" has a slightly different meaning than "case _:" case _: essentially a default, ensuring that the match logic is complete. else: OK, the subject of this match failed, here is our fallback logic. Whether this distinction is important enough to express in code is

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Paul Moore
On Sat, 11 Jul 2020 at 14:39, Ethan Furman wrote: > > On 07/11/2020 04:20 AM, Paul Sokolovsky wrote: > > > Actually, the whole argument in PEP 622 regarding "else:", that its > > placement is ambiguous sounds like a rather artificial write-off. > > Individual "case"'s are aligned together, but

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Ethan Furman
On 07/11/2020 04:20 AM, Paul Sokolovsky wrote: Actually, the whole argument in PEP 622 regarding "else:", that its placement is ambiguous sounds like a rather artificial write-off. Individual "case"'s are aligned together, but suddenly, it's unclear how to align the default case, introduced by

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Paul Sokolovsky
Hello, On Sat, 11 Jul 2020 22:49:09 +1200 Greg Ewing wrote: [] > For the most part, Python indentation follows what people > would naturally do even if they didn't have to. So I think it's > worth looking at what people typically do in other languages > that don't have mandatory indentation. >

[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020-07-11 Thread Greg Ewing
On 11/07/20 10:35 am, Federico Salerno wrote: I feel all those who aren't directly arguing against it are working off the assumption that it is needed for match and case to have different levels of indentation, but is this really true? Is there anything (bar tradition or other subjective