Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-03 Thread Eric Fahlgren
On Fri, Aug 3, 2018 at 6:19 PM Steven D'Aprano wrote: > It needs some work. Something like "Here's an example in the standard > library. On converting it to none-aware version, we realised the std lib > version is buggy, because ...". A couple of sentences. > Yup, that's what I was getting

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-03 Thread Steven D'Aprano
On Fri, Aug 03, 2018 at 06:30:25AM -0700, Eric Fahlgren wrote: > After looking at the code a bit more, I agree, we've uncovered a bug in the > stdlib and the null coalescing version actually fixes it. [...] > But! We are not here to talk about bugs in the email package, this > discussion is

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-03 Thread Eric Fahlgren
On Thu, Aug 2, 2018 at 10:06 PM Alexandre Brault wrote: > I would make the opposite argument and claim that since when policy is > None mangle_from_ is initialised to True and not None, None is likely not a > potential value for policy.mangle_from_. Looking at > Lib/email/_policybase.py where

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-03 Thread Jonathan Fine
Hi Alexandre Thank you for your post. In PEP 505 the context for the example being discussed is: > Some of these are shown below as examples before and after converting to use > the new operators. You wrote: > So yes, *strictly speaking* the two chunks of code are not exactly the same. I see

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Alexandre Brault
On 2018-08-02 7:01 PM, Eric Fahlgren wrote: On Thu, Aug 2, 2018 at 3:39 PM MRAB > wrote: In the relevant code, is policy.mangle_from_ ever None? That's impossible to know, since the initializer where this code originally appears puts no constraints on

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 06:50:47PM +0200, Pål Grønås Drange wrote: > > Reads the same out loud despite being a different operator. > > How are `??`, `.?`, and the others pronounced? Did you read the PEP? It answers that question. https://www.python.org/dev/peps/pep-0505/#reading-expressions

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
On Thu, Aug 2, 2018 at 3:39 PM MRAB wrote: > In the relevant code, is policy.mangle_from_ ever None? > That's impossible to know, since the initializer where this code originally appears puts no constraints on the value of 'policy', it's just assumed to have a 'mangle_from_' member... I would

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread MRAB
On 2018-08-02 22:49, Eric Fahlgren wrote: On Thu, Aug 2, 2018 at 1:22 PM MRAB > wrote: > policy?.mangle_from_ ?? True > True (??? since lhs is None?) > No, it's not 'policy.mangle_from_' that could be None, it's 'policy' that could be

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
On Thu, Aug 2, 2018 at 1:22 PM MRAB wrote: > > policy?.mangle_from_ ?? True > > True (??? since lhs is None?) > > > No, it's not 'policy.mangle_from_' that could be None, it's 'policy' > that could be None (i.e. there's no policy). > In my example, there is a policy, and the value of

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread MRAB
On 2018-08-02 20:03, Eric Fahlgren wrote: From the PEP: > From email/generator.py (and importantly note that there is no way to substitute or for ?? in this situation): > mangle_from_ = True if policy is None else policy.mangle_from_ > After updating: > mangle_from_ =

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Jonathan Fine
Hi Eric [Steve Dower: Eric seems to have found a bug in the PEP. Where to report?] You quoted, from PEP 505, Before > mangle_from_ = True if policy is None else policy.mangle_from_ After > mangle_from_ = policy?.mangle_from_ ?? True You then remarked > I cannot see how these are equivalent I

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
>From the PEP: > >From email/generator.py (and importantly note that there is no way to substitute or for ?? in this situation): > mangle_from_ = True if policy is None else policy.mangle_from_ > After updating: > mangle_from_ = policy?.mangle_from_ ?? True I cannot see how these are equivalent,

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread David Foster
RE none-aware operators in general: +1 overall for the latest version of PEP 505 and the utility of ?? in particular. There are several places in my code that could be simplified with ??. find-pep505.py on my current Django-oriented codebase gives: Total None-coalescing `if` blocks:

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Chris Angelico
On Thu, Aug 2, 2018 at 12:04 AM, Jonathan Fine wrote: > Hi Steve > > Thank you for your reply. > > We're discussing the abstract to PEP 505, which writes > === > The "None-aware attribute access" operator ?. ("maybe dot") evaluates > the complete expression if the left hand side evaluates to a

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Steve Thank you for your reply. We're discussing the abstract to PEP 505, which writes === The "None-aware attribute access" operator ?. ("maybe dot") evaluates the complete expression if the left hand side evaluates to a value that is not None === I gave (42).str as an example. I wrote >

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Steven D'Aprano
On Wed, Aug 01, 2018 at 11:03:05AM +0100, Jonathan Fine wrote: [...] > After my last post, you wrote > > None.?__str__ > > produces None, even though None has a __str__ attribute. > > This surprises me. But I think it follows from the rules in >

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Stephan You wrote > Let me stand up and claim that if a chain consists *only* of None-coalescing > operations, then breaking up the chain by adding parentheses does not > matter, ever. You missed a post I made, 17 minutes before yours. I then believed that PEP 505 specified. #1. (None ?.

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 7:09 PM, Jonathan Fine wrote: > Hi Chris > > We're discussing. >> 10) a ?. b ?. c >> 11) (a ?. b) ?. c > > I asked >> So, are there any values of 'a' for which #10 and #11 don't give the >> same result? > > You replied >> I'm not prepared to put my neck out and say "They

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Stephan Houben
Op wo 1 aug. 2018 11:10 schreef Jonathan Fine : > > > You're right to be cautious. My understanding of PEP 505 is that > #13. a ?. b ?. __str__ > #14. (a ?. b) ?. __str__ > are not equivalent. The first is None, and the other is None.__str__. > That looks like a gotcha. > No. None.?__str__

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Stephan Houben
Op wo 1 aug. 2018 10:50 schreef Chris Angelico : > On Wed, Aug 1, 2018 at 6:45 PM, Jonathan Fine wrote: > > Hi Chris > > > > Thank you for your reply. I think we're making good progress. > > > > You wrote > > > >>> 10) a ?. b ?. c > >>> 11) (a ?. b) ?. c > >> > >> I would parse those

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Chris We're discussing. > 10) a ?. b ?. c > 11) (a ?. b) ?. c I asked > So, are there any values of 'a' for which #10 and #11 don't give the > same result? You replied > I'm not prepared to put my neck out and say "They are absolutely > identical" and have people jump on me with some

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 6:45 PM, Jonathan Fine wrote: > Hi Chris > > Thank you for your reply. I think we're making good progress. > > You wrote > >>> 10) a ?. b ?. c >>> 11) (a ?. b) ?. c >> >> I would parse those differently, but you may be right that they'll >> always have the same final

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Chris Thank you for your reply. I think we're making good progress. You wrote >> 10) a ?. b ?. c >> 11) (a ?. b) ?. c > > I would parse those differently, but you may be right that they'll > always have the same final result. I'd like to get some certainty on this. I'm not aware of any

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 6:00 PM, Jonathan Fine wrote: > Hi Chris > > You wrote: > >> Oh. The equivalent ones are #1 and #2, and #7 and #8, where this >> proposal doesn't change anything. Otherwise, they're not equivalent. > > Are you sure. I'd also expect #10 and #11 to be equivalent. > > By the

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Chris You wrote: > Oh. The equivalent ones are #1 and #2, and #7 and #8, where this > proposal doesn't change anything. Otherwise, they're not equivalent. Are you sure. I'd also expect #10 and #11 to be equivalent. By the way, there's a typo in my examples: 11) (a .? b) ?. c -- Jonathan

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi Chris Thank you for your prompt reply. You wrote > Incorrect. The short-circuiting behaviour ends at any sort of > grouping. It's like how "a < b < c" is not equivalent to "(a < b) < > c", nor to "a < (b < c)". You've told me that my answer B is wrong. But you've not provided your correct

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 5:29 PM, Jonathan Fine wrote: > Hi All > > I have two further questions. I'm keen to clarify what is the > behaviour specified by PEP 505. I'm not, at this time, interested in > why and how PEP 505 specifies behaviour. I just wish, through explicit > examples, to clarify

Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Jonathan Fine
Hi All I have two further questions. I'm keen to clarify what is the behaviour specified by PEP 505. I'm not, at this time, interested in why and how PEP 505 specifies behaviour. I just wish, through explicit examples, to clarify the behaviour that is specified. Here 'a' is an identifier.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread MRAB
On 2018-07-31 20:53, Jonathan Fine wrote: Stephan Houben wrote: Nope, the introduction of the tmp variable changed the semantics. It isn't a "chain" anymore so it breaks shortcutting. I'm confused. Assume 'a' is not defined. With Python's dot (attribute access) we have a.b.c NameError:

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Jonathan Fine
Stephan Houben wrote: > Nope, the introduction of the tmp variable changed the semantics. It isn't a > "chain" anymore so it breaks shortcutting. I'm confused. Assume 'a' is not defined. With Python's dot (attribute access) we have >>> a.b.c NameError: name 'a' is not defined >>> a.(b.c)

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 02:14:19PM -0400, David Mertz wrote: > On Tue, Jul 31, 2018, 1:47 PM Steven D'Aprano wrote: > > > Yes it is. Rhodri is correct, although I admit that I hadn't realised > > this point myself until he pointed it out. (That is why until now I've > > been writing examples

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Stephan Houben
Op di 31 jul. 2018 20:49 schreef Jonathan Fine : > David Mertz wrote: > > > `spam?.eggs?.cheese?.aardvark` is NOT redundant for > > `spam?.eggs.cheese.aardvark`. The two expressions simply do different > > things [...] > > I agree, assuming ?. is a binary operator. It isn't. Given this, in

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Jonathan Fine
David Mertz wrote: > `spam?.eggs?.cheese?.aardvark` is NOT redundant for > `spam?.eggs.cheese.aardvark`. The two expressions simply do different > things [...] I agree, assuming ?. is a binary operator. Given this, in Python (+ PEP 505) one can write tmp = spam ?. eggs val1 = tmp ?.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Rhodri James
On 31/07/18 18:46, Steven D'Aprano wrote: n Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote: [Rhodri James] On 29/07/18 16:12, Abe Dillon wrote: > spam?.eggs.cheese.aardvark # why would you ever do this? If you knew that if you really have something in "spam", your program

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread David Mertz
On Tue, Jul 31, 2018, 1:47 PM Steven D'Aprano wrote: > Yes it is. Rhodri is correct, although I admit that I hadn't realised > this point myself until he pointed it out. (That is why until now I've > been writing examples like "spam?.eggs?.cheese?.aardvark" which is > redundant.) > Again, one

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote: [Rhodri James] > > On 29/07/18 16:12, Abe Dillon wrote: > > > spam?.eggs.cheese.aardvark # why would you ever do this? > > > > If you knew that if you really have something in "spam", your program > > guarantees it will have an "eggs"

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-30 Thread Abe Dillon
[Rhodri James] > We could argue about how intuitive or not these operators are, but they >>> are used in other languages, so they clearly aren't completely >>> unintuitive. >>> >> >> Other languages are other languages. Other languages use the " >> ? >> : " form of the the ternary operator.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-30 Thread Rhodri James
On 29/07/18 16:12, Abe Dillon wrote: spam?.eggs.cheese.aardvark # why would you ever do this? If you knew that if you really have something in "spam", your program guarantees it will have an "eggs" attribute with a "cheese" attribute, etc, you just don't know if "spam" is not None. It's

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-30 Thread Rhodri James
On 28/07/18 21:07, Abe Dillon wrote: [>> = Me] We could argue about how intuitive or not these operators are, but they are used in other languages, so they clearly aren't completely unintuitive. Other languages are other languages. Other languages use the " ? : " form of the the ternary

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Nicholas Chammas
On Sun, Jul 29, 2018 at 10:58 AM Steven D'Aprano wrote: > On Sun, Jul 29, 2018 at 06:32:19AM -0400, David Mertz wrote: > > On Sun, Jul 29, 2018, 2:00 AM Steven D'Aprano > wrote: > > > > > Fine. So it takes them an extra day to learn one more operator. Big > > > deal. It is commonly believed to

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Abe Dillon
[Chris Angelico] > Almost. Except for the problem that "disgusting" is a subjective term. Yes. Thank you for explaining the joke. [Brice Parent] > I don't believe we need spam.eggs.cheese.aardvark? (there is exactly the > same number of use cases). We win a bit in readability as it's closer

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sun, Jul 29, 2018 at 06:32:19AM -0400, David Mertz wrote: > On Sun, Jul 29, 2018, 2:00 AM Steven D'Aprano wrote: > > > Fine. So it takes them an extra day to learn one more operator. Big > > deal. It is commonly believed to take ten years to master a field or > > language. Amortize that one

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Chris Angelico
On Sun, Jul 29, 2018 at 8:32 PM, David Mertz wrote: > I can hardly imagine a stronger bug magnet than PEP 505. The hyperbole in this thread is impressive. Not just "I can hardly imagine anyone PROPOSING a stronger bug magnet". You cannot imagine one even existing. And this is after people have

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Brice Parent
Le 29/07/2018 à 09:12, Abe Dillon a écrit : [...] NO! I'm proposing: spam.eggs.cheese.aardvark? A single POSTFIX operator that has a high priority in the order of operations. I don't believe we need spam?.eggs.cheese?.aardvark, because I don't think it is justified by the small benefits

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Brice Parent
Le 29/07/2018 à 08:02, Steven D'Aprano a écrit : On Sun, Jul 29, 2018 at 12:49:13PM +1200, Greg Ewing wrote: Abe Dillon wrote: others countering that `person.name ` is not how periods are used in natural languages, so using other symbols in unintuitive ways is perfectly

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread David Mertz
On Sun, Jul 29, 2018, 2:00 AM Steven D'Aprano wrote: > Fine. So it takes them an extra day to learn one more operator. Big > deal. It is commonly believed to take ten years to master a field or > language. Amortize that one day over ten years and its virtually > nothing. > This is where being

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Chris Angelico
On Sun, Jul 29, 2018 at 5:12 PM, Abe Dillon wrote: > The syntax of this proposal is almost objectively disgusting. It's truly > horrid. I don't know how many ways to say it. Almost. Except for the problem that "disgusting" is a subjective term. If you want to say that this is *objectively

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Abe Dillon
First of all: Thanks to everyone for explaining everything about the id function. You are all so smart... [Greg Ewing] > Dots have been used for attribute access in so many languages > for so long that it has become the normal and expected syntax > to use. ?. is much more recent. Maybe in

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Chris Angelico
On Sun, Jul 29, 2018 at 3:54 PM, Steven D'Aprano wrote: > Being an implementation detail, CPython is free to change it at any > time, without warning or notice, even in a bug-fix release. If CPython > ever gets a memory manager that can move objects around, as they can > move in Jython and

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sun, Jul 29, 2018 at 12:49:13PM +1200, Greg Ewing wrote: > Abe Dillon wrote: > >others countering that `person.name ` is not how > >periods are used in natural languages, so using other symbols in > >unintuitive ways is perfectly fine. > > Dots have been used for

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sat, Jul 28, 2018 at 10:56:13PM -0500, Abe Dillon wrote: > > > > Python does not have memory locations. > > > > CPython does, form the documentation on the `id` function: No, that is the same id() function as the id() provided by Jython, and IronPython, and Stackless. Like all Python

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-28 Thread Greg Ewing
Abe Dillon wrote: others countering that `person.name ` is not how periods are used in natural languages, so using other symbols in unintuitive ways is perfectly fine. Dots have been used for attribute access in so many languages for so long that it has become the normal

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-28 Thread Chris Angelico
On Sun, Jul 29, 2018 at 1:56 PM, Abe Dillon wrote: >> Python does not have memory locations. > > > CPython does, form the documentation on the `id` function: > >> CPython implementation detail: This is the address of the object in >> memory. Right, which is an important distinction; CPython,

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-28 Thread Abe Dillon
> > Python does not have memory locations. > CPython does, form the documentation on the `id` function: *CPython implementation detail:* This is the address of the object in > memory. I'm not sure what performance implications there would be for adding a __none_check__ or whatever method to

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-28 Thread Chris Angelico
On Sun, Jul 29, 2018 at 6:07 AM, Abe Dillon wrote: > Yes, I thought of that and came to the same conclusion. It's my > understanding that None may not be an actual object, but a special memory > location. I'm not sure though and didn't look it up. Python does not have memory locations. None *is*

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-28 Thread Abe Dillon
> > We could argue about how intuitive or not these operators are, but they > are used in other languages, so they clearly aren't completely unintuitive. Other languages are other languages. Other languages use the " ? : " form of the the ternary operator. That doesn't mean we should adopt that

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-27 Thread Rhodri James
On 26/07/18 22:28, Abe Dillon wrote: The readability issue isn't just a matter of a new set of symbols to learn. It isn't even that the symbols are used in a non-intuitive way (though that doesn't help). We could argue about how intuitive or not these operators are, but they are used in other

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Kyle Lahnakoski
On 2018-07-25 23:53, David Mertz wrote: > On Wed, Jul 25, 2018, 11:27 PM Chris Angelico > wrote: > > > means that you cannot do this: > > >>> NullCoalesce(spam).nil is None > > This IS fundamentally unfixable in a library. > > > Right now, you can still

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Mikhail V
On Thu, Jul 26, 2018 at 5:10 AM, Steven D'Aprano wrote: > On Wed, Jul 25, 2018 at 05:11:08PM -0500, Abe Dillon wrote: >> The problem here is not whether it's explicit. It's about Readability and >> conciseness. Using symbols in place of words almost always harms >> readability in favor of

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 25/07/18 23:11, Abe Dillon wrote: The problem here is not whether it's explicit. It's about Readability and conciseness. Using symbols in place of words almost always harms readability in favor of conciseness. value = person.name if person.name else person ITYM value = person.name if

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 25/07/18 23:36, David Mertz wrote: The fact that a while bunch have people have commented on this subthread while not recognizing that the semantics of the '?.' and the if blocks are entirely different suggests the operators are but magnets. *Entirely* different? Rubbish. It's more like

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Rhodri James
On 26/07/18 05:25, Raymond Hettinger wrote: This PEP is one step further away from Python reading like executable pseudo-code. +1000 -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Nicholas Cole
The curious thing about PEP 505 as far as I can see is that it introduces a new piece of syntax -- and for many people (to judge from the reactions here) a controversial piece of syntax -- to solve what seems to be a rather specific problem. The use-case that seems most discussed is unpacking

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Elazar
Just wanted to note another possibility (most likely to be added to the "rejected solutions" section). Add a prefix "!" operator, which will work similarly to the iterator-unpacking operator "*", but for None. The expression "[!x]" is equivalent to the expression "[] if x is None else [x]". This

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-26 Thread Jonathan Fine
Hi All To start this thread, on 18 July, Steve Dower wrote: > Possibly this is exactly the wrong time to propose the next big syntax > change, since we currently have nobody to declare on it, but since we're > likely to argue for a while anyway it probably can't hurt (and maybe this > will become

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Amit Green
On Thu, Jul 26, 2018 at 1:09 AM, Steven D'Aprano wrote: > On Thu, Jul 26, 2018 at 01:02:47AM -0400, Amit Green wrote: > > > 3. The problem is way deeper than simply adding '?.' and other > operators. > > For real use cases, you also need to say "how far" the an operator can > > "spread" -- and

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 01:02:47AM -0400, Amit Green wrote: > 3. The problem is way deeper than simply adding '?.' and other operators. > For real use cases, you also need to say "how far" the an operator can > "spread" -- and this is real hard to solve. Why do you think that is the case? No

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Wed, Jul 25, 2018 at 11:09:35PM -0400, David Mertz wrote: > Chris Angelica provided a more accurate translation. Do you not see that > the fact that your *second* try at understanding the actual behavior is > still wrong suggest that this operator is a HUGE bug magnet?! Oh what a load of

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Amit Green
On Thu, Jul 26, 2018 at 12:25 AM, Raymond Hettinger < raymond.hettin...@gmail.com> wrote: > It probably is the wrong time and probably can hurt (by introducing > divisiveness when we most need for be focusing on coming together). > > This PEP also shares some traits with PEP 572 in that it

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Thu, Jul 26, 2018 at 12:17 AM David Mertz wrote: > On Thu, Jul 26, 2018 at 12:00 AM Nicholas Chammas < > nicholas.cham...@gmail.com> wrote: > >> Forgive me for being slow. I'm missing what's different in semantics >> between the translation above and Chris's translation below: >> > > You are

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Raymond Hettinger
> On Jul 18, 2018, at 10:43 AM, Steve Dower wrote: > > Possibly this is exactly the wrong time to propose the next big syntax > change, since we currently have nobody to declare on it, but since we're > likely to argue for a while anyway it probably can't hurt (and maybe this > will become

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Thu, Jul 26, 2018 at 12:00 AM Nicholas Chammas < nicholas.cham...@gmail.com> wrote: > Forgive me for being slow. I'm missing what's different in semantics > between the translation above and Chris's translation below: > You are VERY close now. You have more SPAM, so yours is better: In [1]:

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
BTW, even for the "compare to None" issue, the situation in 0.1.1 isn't as bad as you might think. Definitely a "" cannot be compared as "is None". But even there, this works: >>> NullCoalesce(spam).bacon >>> NullCoalesce(spam).bacon == None True >>> NullCoalesce(spam).bacon == 0 False >>>

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 11:09 PM David Mertz wrote: > On Wed, Jul 25, 2018 at 10:50 PM Nicholas Chammas < > nicholas.cham...@gmail.com> wrote: > >> Indeed. Thanks for the counter-example. I think the correct translation >> is as follows: >> food = spam?.eggs?.bacon >> Becomes: >> food =

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018, 11:27 PM Chris Angelico wrote: > > That's a bug in my proxy too. I'll figure out how to fix it in 0.1.2 > soon. > > This is early alpha, and the things you're noting are valuable bug > reports. > > But none of this is fundamentally unfixable in a library, nor even > >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Chris Angelico
On Thu, Jul 26, 2018 at 1:19 PM, David Mertz wrote: > On Wed, Jul 25, 2018 at 11:08 PM Chris Angelico wrote: >> >> > Yeah, yeah. I know it's alpha software I wrote two nights ago, and >> > slightly >> > patched 5 minutes before that post. You fixed those concerns; I'll >> > happily >> > take

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018 at 11:08 PM Chris Angelico wrote: > > Yeah, yeah. I know it's alpha software I wrote two nights ago, and > slightly > > patched 5 minutes before that post. You fixed those concerns; I'll > happily > > take PRs on fixing them better. > > PRs? Nope. I don't think it's

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018 at 10:50 PM Nicholas Chammas < nicholas.cham...@gmail.com> wrote: > Indeed. Thanks for the counter-example. I think the correct translation is > as follows: > food = spam?.eggs?.bacon > Becomes: > food = None > if spam is not None and spam.eggs is not None: >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Chris Angelico
On Thu, Jul 26, 2018 at 12:56 PM, David Mertz wrote: > On Wed, Jul 25, 2018 at 10:41 PM Chris Angelico wrote: >> >> A bit problematic. But after (a) figuring out that your module is >> named "coalesce" even though I installed "coalescing" AND (b) going >> and separately installing wrapt, and

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Chris Angelico
On Thu, Jul 26, 2018 at 12:45 PM, David Mertz wrote: > On Wed, Jul 25, 2018 at 10:29 PM Chris Angelico wrote: >> It is *actually impossible* to >> perfectly represent short-circuiting semantics in Python! > > > It's INCREDIBLY EASY to represent short-circuiting semantics in Python! What > on

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018 at 10:41 PM Chris Angelico wrote: > A bit problematic. But after (a) figuring out that your module is > named "coalesce" even though I installed "coalescing" AND (b) going > and separately installing wrapt, and finally (c) doing the import that > you didn't mention, we still

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 10:12 PM David Mertz wrote: > On Wed, Jul 25, 2018 at 9:47 PM Nicholas Chammas < > nicholas.cham...@gmail.com> wrote: > >> > That is disingenuous, I think. Can this raise an AttributeError? >>> > spam?.eggs?.bacon >>> > Of course it can! And this is exactly the

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018 at 10:29 PM Chris Angelico wrote: > food = spam?.eggs?.bacon > > can be rewritten as > > _tmp = spam > if _tmp is not None: > _tmp = _tmp.eggs > if _tmp is not None: > _tmp = _tmp.bacon > food = _tmp > Yes, that looks right. Well, you need a `del _tmp` at

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Chris Angelico
On Thu, Jul 26, 2018 at 12:30 PM, David Mertz wrote: > Btw. Here's a way of spelling the proposed syntax that gets the semantics > right: > # pip install coalescing NullCoalesce(spam).eggs.bacon Let's try it. rosuav@sikorsky:~$ sudo python3 -m pip install coalescing Collecting

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
So now at least TWO proponents of 505 cannot successfully translate a very simple example taken almost directly from the PEP! Is that REALLY a good argument for it being helpful, and not being a bug magnet?! On Wed, Jul 25, 2018 at 9:57 PM Chris Angelico wrote: > On Thu, Jul 26, 2018 at 11:45

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
On Wed, Jul 25, 2018 at 9:47 PM Nicholas Chammas wrote: > > That is disingenuous, I think. Can this raise an AttributeError? >> > spam?.eggs?.bacon >> > Of course it can! And this is exactly the pattern used in many examples >> in >> > the PEP and the discussion. So the PEP would create a

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 9:20 PM Chris Angelico wrote: > On Thu, Jul 26, 2018 at 11:02 AM, David Mertz wrote: > > That is disingenuous, I think. Can this raise an AttributeError? > > > > spam?.eggs?.bacon > > > > Of course it can! And this is exactly the pattern used in many examples > in >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread James Lu
What if we used ? after the statement beginning? name ?= person.name custom_query ?= entity.get_query(context) # Becomes None if entity is None. Raise an exception if entity is not None and get_query is None or undefined. custom_query ??= entity.get_query(context) # If entity, entity.get_query,

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Tue, Jul 24, 2018 at 08:07:36AM -0400, Richard Damon wrote: > The fact that you changed NullCoalesce into Foo to show lack of > explicitness seems a straw-man. I understood Rhodri as making the point that if you don't know what NullCoalesce means or does, it might as well be called Foo.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Wed, Jul 25, 2018 at 12:12:40PM -0400, Nicholas Chammas wrote: > When something is "explicit", as I understand it, that means it does what > it says on the cover. There is no unstated behavior. The plain meaning of > `v = a?.b` is that it expands to the longer form (`v = a; if a.b ...`), and >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Greg Ewing
David Mertz wrote: Sorry. From my tablet. "Bug magnets" (it really, really wants to autocorrect that) At least it didn't correct it to "butt magnets". :-) -- Greg ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Abe Dillon
*sorry, cat hit "send"... Just reading those examples made me want to cry and go hide in a dark dark cave and never come out. I'm sure using actual variable names would help a bit, but not much. As for the non-english nature of: value = person.name I highly disagree with the argument that since

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Abe Dillon
> > The two statements you wrote are not the same. The first statement will > error out if person is None. That's my bad. I was copying off of an erroneous example. Thanks for correcting me. The proposed None-aware operators are specifically designed to handle > variables that may be None. >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 6:11 PM Abe Dillon wrote: > The problem here is not whether it's explicit. It's about Readability and > conciseness. Using symbols in place of words almost always harms > readability in favor of conciseness. > > value = person.name if person.name else person > > almost

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
Sorry. From my tablet. "Bug magnets" (it really, really wants to autocorrect that) And yes, the problem is that the equivalent is actually: v = a if v is not None: v=a.b The semantics are simply not the ones that are intuitive to most people reading 'v = a?.b' On Wed, Jul 25, 2018,

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Elazar
On Wed, Jul 25, 2018 at 3:11 PM Abe Dillon wrote: > The problem here is not whether it's explicit. It's about Readability and > conciseness. Using symbols in place of words almost always harms > readability in favor of conciseness. > > value = person.name if person.name else person > > almost

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Abe Dillon
> > The fact that a while bunch have people have commented on this subthread > while not recognizing that the semantics of the '?.' and the if blocks are > entirely different suggests the operators are but magnets. > Can you explain? What do you mean by "the operators are but magnets"? The "None

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 6:36 PM David Mertz wrote: > The fact that a while bunch have people have commented on this subthread > while not recognizing that the semantics of the '?.' and the if blocks are > entirely different suggests the operators are but magnets. > > On Wed, Jul 25, 2018, 5:17

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread David Mertz
The fact that a while bunch have people have commented on this subthread while not recognizing that the semantics of the '?.' and the if blocks are entirely different suggests the operators are but magnets. On Wed, Jul 25, 2018, 5:17 PM Nicholas Chammas wrote: > On Mon, Jul 23, 2018 at 6:05 PM

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Abe Dillon
The problem here is not whether it's explicit. It's about Readability and conciseness. Using symbols in place of words almost always harms readability in favor of conciseness. value = person.name if person.name else person almost reads like english (aside from being a weird and totally uncommon

  1   2   3   >