[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-11 Thread Paul Sokolovsky
Hello, On Tue, 12 Jan 2021 00:11:33 +1000 Nick Coghlan wrote: > On Sun, 10 Jan 2021, 7:37 pm Paul Sokolovsky, > wrote: > > > And I patiently continue this thread, hoping that people whose > > argument would be along the lines of "I teach Python, and I don't > > want to teach my students 2 ways

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-11 Thread Nick Coghlan
On Sun, 10 Jan 2021, 7:37 pm Paul Sokolovsky, wrote: > And I patiently continue this thread, hoping that people whose argument > would be along the lines of "I teach Python, and I don't want to teach > my students 2 ways of doing the same thing, and which way use when. Why, > if PEP634 offers jus

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-10 Thread Paul Sokolovsky
Hello, On Sun, 10 Jan 2021 12:08:05 +1000 Nick Coghlan wrote: [] > PEP 634 doesn't have that feature for class patterns in general, only > for classes like data classes, where the constructor signature is > carefully aligned with the match arguments. You see, if PEP622/PEP634 contained clause

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Nick Coghlan
On Sun, 10 Jan 2021, 2:55 am Paul Moore, wrote: > On Sat, 9 Jan 2021 at 14:54, Nick Coghlan wrote: > > [...] > > And I've already said I'd be fine with making the colon mandatory if the > SC share that view. > > So the response to my comment that omitting the colon makes it hard to > see that it

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Moore
On Sat, 9 Jan 2021 at 14:54, Nick Coghlan wrote: [...] > And I've already said I'd be fine with making the colon mandatory if the SC > share that view. So the response to my comment that omitting the colon makes it hard to see that it's a dictionary unpacking is either "don't use that form if y

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Sokolovsky
Hello, On Sun, 10 Jan 2021 01:42:25 +1000 Nick Coghlan wrote: > On Sat, 9 Jan 2021, 8:50 pm Paul Sokolovsky, > wrote: > > > > > > > The key difference relative to PEP 634 is that even when the code > > > author uses the shorthand form, *readers* will still get at least > > > the "as" keyword a

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Nick Coghlan
On Sat, 9 Jan 2021, 8:50 pm Paul Sokolovsky, wrote: > > > > The key difference relative to PEP 634 is that even when the code > > author uses the shorthand form, *readers* will still get at least the > > "as" keyword as a prompt, > > Ok, so let's summarize the alternatives: > > 1. PEP634, which s

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Nick Coghlan
On Sun, 10 Jan 2021, 12:54 am Nick Coghlan, wrote: > > > On Sun, 10 Jan 2021, 12:22 am Paul Moore, wrote: > >> On Sat, 9 Jan 2021 at 13:53, Antoine Pitrou wrote: >> >> >> The dictionary destructuring can act as an example. We know Nick's >> position: >> >> case {"text": message, "color": c}

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Nick Coghlan
On Sun, 10 Jan 2021, 12:22 am Paul Moore, wrote: > On Sat, 9 Jan 2021 at 13:53, Antoine Pitrou wrote: > > > So, opposing Nick's proposal on the basis that it "looks like a set" is > > just like opposing set literals on the basis they they "look like a > > dict". > > That's not what I was doing (

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Sokolovsky
Hello, On Sat, 9 Jan 2021 14:49:19 +0100 Antoine Pitrou wrote: > On Sat, 9 Jan 2021 12:17:32 + > Paul Moore wrote: > > > On Sat, 9 Jan 2021 at 10:52, Paul Sokolovsky > > wrote: > > > > case {"host" as host, "port" as port}: > > > > > > There're 2 obvious problems with it: > > > > >

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Antoine Pitrou
Le 09/01/2021 à 15:18, Paul Moore a écrit : > > But the PEP 642 form: > > case {"text" as message, "color" as c}: > > is essentially identical except for using "as" rather than a colon. My view > is: > > 1. Nowhere else in Python does "as" indicate a dictionary, and braces > alone don't (

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Moore
On Sat, 9 Jan 2021 at 13:53, Antoine Pitrou wrote: > So, opposing Nick's proposal on the basis that it "looks like a set" is > just like opposing set literals on the basis they they "look like a > dict". That's not what I was doing (I can't comment on what Paul S intended, though). My position i

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Antoine Pitrou
On Sat, 9 Jan 2021 12:17:32 + Paul Moore wrote: > On Sat, 9 Jan 2021 at 10:52, Paul Sokolovsky wrote: > > > case {"host" as host, "port" as port}: > > > > There're 2 obvious problems with it: > > > > a) In Python, {} with things inside it, but no ":" inside it, is a set, > > set. > > b) Ev

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Moore
On Sat, 9 Jan 2021 at 10:52, Paul Sokolovsky wrote: > > case {"host" as host, "port" as port}: > > There're 2 obvious problems with it: > > a) In Python, {} with things inside it, but no ":" inside it, is a set, > set. > b) Everywhere else in Python, thing on the left of "as" gets into > thing on

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-09 Thread Paul Sokolovsky
Hello, On Sat, 9 Jan 2021 12:27:45 +1000 Nick Coghlan wrote: > On Sat, 9 Jan 2021, 7:07 am Joseph Martinot-Lagarde, > wrote: > > > Paul Sokolovsky wrote: > > > Hello, > > > On Tue, 5 Jan 2021 20:37:27 +1000 > > > Nick Coghlan ncogh...@gmail.com wrote: > > > > object(host=as host, port=as p

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-08 Thread Nick Coghlan
On Sat, 9 Jan 2021, 7:07 am Joseph Martinot-Lagarde, wrote: > Paul Sokolovsky wrote: > > Hello, > > On Tue, 5 Jan 2021 20:37:27 +1000 > > Nick Coghlan ncogh...@gmail.com wrote: > > > object(host=as host, port=as port}:", but that > > > couldn't ever be > > > I'd like to point out the weirdness of

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-08 Thread Joseph Martinot-Lagarde
Paul Sokolovsky wrote: > Hello, > On Tue, 5 Jan 2021 20:37:27 +1000 > Nick Coghlan ncogh...@gmail.com wrote: > > object(host=as host, port=as port}:", but that > > couldn't ever be > > I'd like to point out the weirdness of the "as" syntax when applied > to > positional arguments, e.g.: > case [as

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-05 Thread Paul Sokolovsky
Hello, On Tue, 5 Jan 2021 20:37:27 +1000 Nick Coghlan wrote: > > > object(host=as host, port=as port}:", but that couldn't ever be I'd like to point out the weirdness of the "as" syntax when applied to positional arguments, e.g.: case [as x, as y]: case Cls(as x, as y): That feels unnatural,

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-05 Thread Nick Coghlan
On Mon, 4 Jan 2021 at 18:38, Paul Moore wrote: > > On Sun, 3 Jan 2021 at 23:38, Nick Coghlan wrote: > > > > The instance attribute syntax arose from trying to deal with two problems > > from class patterns in PEP 634: > > > > * "ATTR=TARGET" using "=" to bind to the right instead of to the left

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-04 Thread Paul Moore
On Sun, 3 Jan 2021 at 23:38, Nick Coghlan wrote: > > The instance attribute syntax arose from trying to deal with two problems > from class patterns in PEP 634: > > * "ATTR=TARGET" using "=" to bind to the right instead of to the left > * no subsequent path to ever offering a syntax for *retrievi

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Nick Coghlan
On Mon, 4 Jan 2021, 4:34 am Ethan Furman, wrote: > On 1/3/21 8:50 AM, Paul Moore wrote: > > > Personally, I read it and was horribly confused. > > >> case object{.host as host, .port as port}: > >> pass > > Leading periods is a big no-go for me, for all the reasons listed in

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Nick Coghlan
On Mon, 4 Jan 2021, 2:50 am Paul Moore, wrote: > On Sun, 3 Jan 2021 at 16:26, Barry Scott wrote: > > I read the above and believe I know what it meant without needing to > read the PEP in detail. > > I like that a lot. > > Personally, I read it and was horribly confused. I worked out most of > i

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Nick Coghlan
On Mon, 4 Jan 2021, 2:19 am Barry Scott, wrote: > > I quickly read 642 v3 and missed an explanation about why the syntax to > match a string object is > str{} and not str. Are you saying that I MUST use {} so that when case is > parsed its clear that its a class > with no constraints? > Yes. "s

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Paul Sokolovsky
Hello, On Sun, 3 Jan 2021 16:50:33 + Paul Moore wrote: > On Sun, 3 Jan 2021 at 16:26, Barry Scott > wrote: > > I read the above and believe I know what it meant without needing > > to read the PEP in detail. I like that a lot. > > Personally, I read it and was horribly confused. I worked

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Ethan Furman
On 1/3/21 8:50 AM, Paul Moore wrote: Personally, I read it and was horribly confused. case object{.host as host, .port as port}: pass Leading periods is a big no-go for me, for all the reasons listed in the original thread. I have not read the full PEP, so take this

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Paul Moore
On Sun, 3 Jan 2021 at 16:26, Barry Scott wrote: > I read the above and believe I know what it meant without needing to read the > PEP in detail. > I like that a lot. Personally, I read it and was horribly confused. I worked out most of it, but I would *not* count it as intuitive or natural. Spe

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Antoine Pitrou
On Sun, 3 Jan 2021 16:19:01 + Barry Scott wrote: > > > > I’ll also quote the example match statement from the PEP abstract, > > which extracts “host” and “port” details from a 2 item sequence, a > > mapping with “host” and “port” keys, any object with “host” and “port” > > attributes, or a “h

[Python-Dev] Re: PEP 642 v3: Explicit patterns for structured pattern matching

2021-01-03 Thread Barry Scott
> On 3 Jan 2021, at 15:21, Nick Coghlan wrote: > > I’ve made a final round of updates to PEP 642 and submitted it to the > Steering Council for consideration alongside PEP 634. > > As usual, the rendered version can be found here: > https://www.python.org/dev/peps/pep-0642/ > > There's a Disc