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

2018-07-25 Thread Steven D'Aprano
On Tue, Jul 24, 2018 at 07:02:54AM -0400, David Mertz wrote: > On Tue, Jul 24, 2018, 5:50 AM Steven D'Aprano wrote: > > > But what certainly *is* implicity is David Mertz' suggestion for a > > magical None-aware proxy: > > > > x.attribute > > > > The only way to tell whether that was an ordin

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. Ther

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 https://mail.python.org/mailman/l

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. > Yes,

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 rea

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, 7:01

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 rea

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 PM

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 G

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 u

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

2018-07-25 Thread Nicholas Chammas
On Wed, Jul 25, 2018 at 12:12 PM Nicholas Chammas < nicholas.cham...@gmail.com> wrote: > On Mon, Jul 23, 2018 at 6:05 PM Giampaolo Rodola' > wrote: > >> This: >> >> v = a?.b >> >> ...*implicitly* checks if value is not None [and continues execution]. >> This: >> >> v = a >> if a.b is

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

2018-07-25 Thread Nicholas Chammas
On Mon, Jul 23, 2018 at 6:05 PM Giampaolo Rodola' wrote: > This: > > v = a?.b > > ...*implicitly* checks if value is not None [and continues execution]. > This: > > v = a > if a.b is not None: > v = a.b > > ...*explicitly* checks if value is not None and continues execution. >

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

2018-07-24 Thread David Mertz
On Tue, Jul 24, 2018, 9:09 AM Chris Angelico wrote: > >>> x = Foo(cfg).user.profile > >>> x.food > > Remember, these lines could be a very long way apart. You could pass > 'x' to a function unrelated to the line of code that created it. And > 'x.food' still has to have the magic. You can't mandat

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

2018-07-24 Thread David Mertz
I *definitely* don't think a little tool I wrote in a couple hours last night belongs in the standard library (with most of the heavy lifting actually done by wrapt—which is really well designed, and is also not in the standard library). I also don't think PyMaybe belongs there, even though it's a

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

2018-07-24 Thread Chris Angelico
On Tue, Jul 24, 2018 at 11:02 PM, David Mertz wrote: > On Tue, Jul 24, 2018, 7:38 AM Rhodri James wrote: >> >> On 24/07/18 12:02, David Mertz wrote: >> > Every use I've suggested for the magic proxy is similar to: >> > >> >NullCoalesce(cfg).user.profile.food >> > >> > Yes, the class is magic.

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

2018-07-24 Thread Rhodri James
On 24/07/18 14:02, David Mertz wrote: On Tue, Jul 24, 2018, 7:38 AM Rhodri James wrote: I'm still of the opinion that both approaches are trying to solve a problem that's too niche to merit them, BTW. That doesn't make sense to me. You think my little library shouldn't be allowed on PyPI? I

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

2018-07-24 Thread David Mertz
On Tue, Jul 24, 2018, 7:38 AM Rhodri James wrote: > On 24/07/18 12:02, David Mertz wrote: > > Every use I've suggested for the magic proxy is similar to: > > > >NullCoalesce(cfg).user.profile.food > > > > Yes, the class is magic. That much more so in the library I published > last > > night t

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

2018-07-24 Thread Rhodri James
On 24/07/18 13:07, Richard Damon wrote: The fact that you changed NullCoalesce into Foo to show lack of explicitness seems a straw-man. Words are FULL of meaning, while symbols are less so. The biggest issue I see with the use of ? here is that ? does have some meaning, it says we are going to

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

2018-07-24 Thread Grégory Lielens
Both approaches should not be exposed as core language, but as facilitating tools to be used if, in your application, you have to traverse deep semi-regular attributes hierarchies. The operator approach, by definition, is part of the core, so -1 The wrapper does not need to be included in python,

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

2018-07-24 Thread Richard Damon
> On Jul 24, 2018, at 7:37 AM, Rhodri James wrote: > >> On 24/07/18 12:02, David Mertz wrote: >> Every use I've suggested for the magic proxy is similar to: >> NullCoalesce(cfg).user.profile.food >> Yes, the class is magic. That much more so in the library I published last >> night that utili

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

2018-07-24 Thread Rhodri James
On 24/07/18 12:56, Grégory Lielens wrote: On Tuesday, July 24, 2018 at 1:38:42 PM UTC+2, Rhodri James wrote: -snip- I'm still of the opinion that both approaches are trying to solve a problem that's too niche to merit them, BTW. That's also my impression. Hence the second approach: it does no

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

2018-07-24 Thread Grégory Lielens
On Tuesday, July 24, 2018 at 1:38:42 PM UTC+2, Rhodri James wrote: > > -snip- > I'm still of the opinion that both approaches are trying to solve a > problem that's too niche to merit them, BTW. That's also my impression. Hence the second approach: it does not require any change to python, i

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

2018-07-24 Thread Rhodri James
On 24/07/18 12:02, David Mertz wrote: Every use I've suggested for the magic proxy is similar to: NullCoalesce(cfg).user.profile.food Yes, the class is magic. That much more so in the library I published last night that utilizes wrapt.ObjectProxy. But it's also pretty explicit in that an act

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

2018-07-24 Thread David Mertz
On Tue, Jul 24, 2018, 5:50 AM Steven D'Aprano wrote: > But what certainly *is* implicity is David Mertz' suggestion for a > magical None-aware proxy: > > x.attribute > > The only way to tell whether that was an ordinary attribute lookup or a > none-aware lookup would be to carefully inspect x

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

2018-07-24 Thread Giampaolo Rodola'
On Tue, Jul 24, 2018 at 11:50 AM Steven D'Aprano wrote: > > On Tue, Jul 24, 2018 at 12:05:14AM +0200, Giampaolo Rodola' wrote: > > > This: > > > > v = a?.b > > > > ...*implicitly* checks if value is not None [and continues execution]. > > Do you agree that: > > obj.attribute > x + 1 >

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

2018-07-24 Thread Steven D'Aprano
On Tue, Jul 24, 2018 at 12:05:14AM +0200, Giampaolo Rodola' wrote: > This: > > v = a?.b > > ...*implicitly* checks if value is not None [and continues execution]. Do you agree that: obj.attribute x + 1 func(arg) explicitly looks up an attribute on obj, explicitly adds 1 to x,

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

2018-07-24 Thread Giampaolo Rodola'
On Tue, Jul 24, 2018 at 2:22 AM MRAB wrote: > >> > It > >> > does so by introducing a brand new operator ("?") which can be spelled > >> > in two forms ("a?.b" and "a?[b]") by using two adjacent symbols not > >> > interrupted by any space, which is an absolute first in the Python > >> > syntax >

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

2018-07-24 Thread Paul Moore
On 24 July 2018 at 08:38, Grégory Lielens wrote: > > > On Tuesday, July 24, 2018 at 9:28:02 AM UTC+2, Brice Parent wrote: >> >> Le 24/07/2018 à 00:39, Chris Angelico a écrit : >> > On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans wrote: >> ... >> > What about: >> > >> > 5 < x < 10 >> > >> > Can yo

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

2018-07-24 Thread Grégory Lielens
On Tuesday, July 24, 2018 at 9:28:02 AM UTC+2, Brice Parent wrote: > > Le 24/07/2018 à 00:39, Chris Angelico a écrit : > > On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans > wrote: > ... > > What about: > > > > 5 < x < 10 > > > > Can you add parentheses to that to "make precedence and evaluation

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

2018-07-24 Thread Chris Angelico
On Tue, Jul 24, 2018 at 5:26 PM, Brice Parent wrote: > Le 24/07/2018 à 00:39, Chris Angelico a écrit : >> >> On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans wrote: > > ... >> >> What about: >> >> 5 < x < 10 >> >> Can you add parentheses to that to "make precedence and evaluation order >> clear"?

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

2018-07-24 Thread Brice Parent
Le 24/07/2018 à 00:39, Chris Angelico a écrit : On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans wrote: ... What about: 5 < x < 10 Can you add parentheses to that to "make precedence and evaluation order clear"? Correct me if I'm wrong, but to my knowledge, this is just a shorthand to `5 < x

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

2018-07-23 Thread MRAB
On 2018-07-23 23:05, Giampaolo Rodola' wrote: On Mon, Jul 23, 2018 at 6:53 PM Steven D'Aprano wrote: On Mon, Jul 23, 2018 at 02:04:17PM +0200, Giampaolo Rodola' wrote: > "a?.b" does two and that's a fundamental difference (explicitness). How is "two things" less explicit than "one thing"? Com

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

2018-07-23 Thread Thomas Jollans
On 24/07/18 00:39, Chris Angelico wrote: > On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans wrote: >> On 18/07/18 19:43, Steve Dower wrote: >>> When a ``None``-aware operator is present, the left-to-right evaluation >>> may be >>> short-circuited. For example, ``await a?.b(c).d?[e]`` is evaluated::

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

2018-07-23 Thread Chris Angelico
On Tue, Jul 24, 2018 at 8:22 AM, Thomas Jollans wrote: > On 18/07/18 19:43, Steve Dower wrote: >> When a ``None``-aware operator is present, the left-to-right evaluation >> may be >> short-circuited. For example, ``await a?.b(c).d?[e]`` is evaluated:: >> >> _v = a >> if _v is not None: >>

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

2018-07-23 Thread Thomas Jollans
On 18/07/18 19:43, Steve Dower wrote: > When a ``None``-aware operator is present, the left-to-right evaluation > may be > short-circuited. For example, ``await a?.b(c).d?[e]`` is evaluated:: > >     _v = a >     if _v is not None: >     _v = _v.b >     _v = _v(c) >     _v = _v.d >    

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

2018-07-23 Thread Chris Angelico
On Tue, Jul 24, 2018 at 8:05 AM, Giampaolo Rodola' wrote: > The argument about this is that '?.' short-circuits execution > *silently*. Instead of AttributeError you get None. You may chain ?. > in order to lazily traverse a long tree, inadvertently assign None to > a variable, continue code execu

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

2018-07-23 Thread Giampaolo Rodola'
On Mon, Jul 23, 2018 at 6:53 PM Steven D'Aprano wrote: > > On Mon, Jul 23, 2018 at 02:04:17PM +0200, Giampaolo Rodola' wrote: > > "a?.b" does two and that's a fundamental difference (explicitness). > > How is "two things" less explicit than "one thing"? > Comments like the above is why I think tha

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

2018-07-23 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 11:54:19AM +1000, Steven D'Aprano wrote: > In my opinion, writing > > expression if expression is None else default > > is the *opposite* of Pythonic, it is verbose and the DRY violation is > inelegant (as well as inefficient). I'd much rather use: > > expressio

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

2018-07-23 Thread MRAB
On 2018-07-23 13:04, Giampaolo Rodola' wrote: On Mon, Jul 23, 2018 at 3:12 AM Steven D'Aprano wrote: > ? has no spaces, it's literally "variable names interrupted by > question marks" and evaluation can stop at any time while scanning the > line from left to right. Just like ordinary attribute

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

2018-07-23 Thread MRAB
On 2018-07-23 10:51, Steve Dower wrote: [snip] False: 'a?.b' is totally different from 'a.b' - The expression 'a.b' either results in 'a.b' or AttributeError (assuming no descriptors are involved). The expression 'a?.b' either results in 'a.b' or Non

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

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 02:04:17PM +0200, Giampaolo Rodola' wrote: [I wrote this] > > This is the point I was making earlier: you accept existing punctuation > > doing these things: > > > > try: > > obj.spam.egsg.tomato.cheese # oops a typo > > except AttributeError: > > #

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

2018-07-23 Thread Mikhail V
I personally do almost only classical programming, and I am somewhat opposed to OOP in general. So here my somewhat outlandish view, (and I am biased becase I will probably never need this feature). First thoughts after reading the PEP: what is so super-special and fundamental about None value? Is

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

2018-07-23 Thread Steve Dower
On 23Jul2018 1530, David Mertz wrote: Of course I don't mean that if implemented the semantics would be ambiguous... rather, the proper "swallowing" of different kinds of exceptions is not intuitively obvious, not even to you, Steve.  And if some decision was reached and documented, it would re

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

2018-07-23 Thread C Anthony Risinger
On Mon, Jul 23, 2018 at 7:46 AM, Grégory Lielens wrote: > Paul Moore wrote: >> >> This is my impression, as well. It seems like something that's helpful >> in dealing with unstructured object hierarchies with lots of optional >> attributes - which is where JSON tends to be used. >> >> But given

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

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 12:09:00PM +0100, Steve Dower wrote: > On 23Jul2018 1145, Antoine Pitrou wrote: > > > >Le 23/07/2018 à 12:38, Steve Dower a écrit : > >> > >>General comment to everyone (not just Antoine): these arguments have > >>zero value to me. Feel free to keep making them, but I am uni

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

2018-07-23 Thread Giampaolo Rodola'
On Mon, Jul 23, 2018 at 11:52 AM Steve Dower wrote: > I'm borderline on ?[] right now. Honestly, I think it works best if it > also silently handles LookupError (e.g. for traversing a loaded JSON > dict), but then it's inconsistent with ?. which I think works best if it > handles None but allows

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

2018-07-23 Thread David Mertz
On Mon, Jul 23, 2018 at 5:52 AM Steve Dower wrote: > The PEP author is unsure about how it works > --- > I wish this statement had come with some context, because the only thing > I'm unsure about is what I'm supposed to be unsure about. > In general—as I

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

2018-07-23 Thread Andre Roberge
On Mon, Jul 23, 2018 at 6:52 AM Steve Dower wrote: > Responding to a few more ideas that have come up here. > ​Thank you for the clarifications.​ ​I'm trying to wrap my head around the various facets of None aware operators proposal after reading the whole discussion - as well as having read t

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

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 10:48:23AM +0100, Steve Dower wrote: > On 23Jul2018 0151, Steven D'Aprano wrote: > >What if there was a language > >supported, non-hackish way to officially delay evaluation of > >expressions until explicitly requested? > > The current spelling for this is "lambda: delayed-

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

2018-07-23 Thread Nicholas Cole
On Mon, Jul 23, 2018 at 2:37 PM Mark E. Haase wrote: >> What does a scan through the existing core library say? > > > Please read the PEP before you shoot it down. It answers this _exact_ > question. My apologies. I'd missed the line where it says the examples were taken from the core library.

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

2018-07-23 Thread Mark E. Haase
On Mon, Jul 23, 2018 at 2:23 AM Nicholas Cole wrote: > One issue for me is that the trivial case is already a one-liner: > > if a is None: a = 10 > Yes, if you have no indentation and a 1-character name, then it fits on a single line. If you have a longer expression and/or side effects, then it'

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

2018-07-23 Thread Grégory Lielens
Paul Moore wrote: > > This is my impression, as well. It seems like something that's helpful > in dealing with unstructured object hierarchies with lots of optional > attributes - which is where JSON tends to be used. > > But given that, I'm really much more interested in seeing the new > operator

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

2018-07-23 Thread Giampaolo Rodola'
On Mon, Jul 23, 2018 at 3:12 AM Steven D'Aprano wrote: > > ? has no spaces, it's literally "variable names interrupted by > > question marks" and evaluation can stop at any time while scanning the > > line from left to right. > > Just like ordinary attribute access. > > This is the point I was mak

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

2018-07-23 Thread Paul Moore
On 23 July 2018 at 12:39, Grégory Lielens wrote: > Maybe it would help if you mention in which context you will benefit the > most? If the python sub-community related to this context agree "?? and > friends" is a good idea, then it will add weight to the proposal. Else, > probably better to forge

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

2018-07-23 Thread Grégory Lielens
Maybe it would help if you mention in which context you will benefit the most? If the python sub-community related to this context agree "?? and friends" is a good idea, then it will add weight to the proposal. Else, probably better to forget it. It seems related to JSON, but as I have never us

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

2018-07-23 Thread Antoine Pitrou
Le 23/07/2018 à 13:09, Steve Dower a écrit : > On 23Jul2018 1145, Antoine Pitrou wrote: >> >> Le 23/07/2018 à 12:38, Steve Dower a écrit : >>> >>> General comment to everyone (not just Antoine): these arguments have >>> zero value to me. Feel free to keep making them, but I am uninterested. >> >>

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

2018-07-23 Thread Nicholas Cole
On Mon, Jul 23, 2018 at 8:08 AM Grégory Lielens wrote: > > > > On Monday, July 23, 2018 at 8:24:45 AM UTC+2, Nicholas Cole wrote: > >> And that leads to a simple question: how many times does this actually >> occur in real-world by python code? -- i.e. how many times do I want >> to check the valu

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

2018-07-23 Thread Steve Dower
On 23Jul2018 1145, Antoine Pitrou wrote: Le 23/07/2018 à 12:38, Steve Dower a écrit : General comment to everyone (not just Antoine): these arguments have zero value to me. Feel free to keep making them, but I am uninterested. So you're uninterested in learning from past mistakes? You sound

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

2018-07-23 Thread Antoine Pitrou
Le 23/07/2018 à 12:38, Steve Dower a écrit : > > General comment to everyone (not just Antoine): these arguments have > zero value to me. Feel free to keep making them, but I am uninterested. So you're uninterested in learning from past mistakes? You sound like a child who thinks their demand

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

2018-07-23 Thread Steve Dower
On 23Jul2018 1129, Antoine Pitrou wrote: Le 23/07/2018 à 12:25, Steve Dower a écrit : On 23Jul2018 , Antoine Pitrou wrote: On Mon, 23 Jul 2018 10:51:31 +0100 Steve Dower wrote: Which is the most important operator? - Personally, I think '?.' is the m

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

2018-07-23 Thread Antoine Pitrou
Le 23/07/2018 à 12:25, Steve Dower a écrit : > On 23Jul2018 , Antoine Pitrou wrote: >> On Mon, 23 Jul 2018 10:51:31 +0100 >> Steve Dower wrote: >>> >>> Which is the most important operator? >>> - >>> >>> Personally, I think '?.' is the most valuable. >> >>

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

2018-07-23 Thread Steve Dower
On 23Jul2018 , Antoine Pitrou wrote: On Mon, 23 Jul 2018 10:51:31 +0100 Steve Dower wrote: Which is the most important operator? - Personally, I think '?.' is the most valuable. For me, it's the most contentious. The fact that a single '?' added to a

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

2018-07-23 Thread Antoine Pitrou
On Mon, 23 Jul 2018 10:51:31 +0100 Steve Dower wrote: > > Which is the most important operator? > - > > Personally, I think '?.' is the most valuable. For me, it's the most contentious. The fact that a single '?' added to a regular line of Python code can sh

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

2018-07-23 Thread Steve Dower
Responding to a few more ideas that have come up here. Again, apologies for not directing them to the original authors, but I want to focus on the ideas that are leading towards a more informed decision, and not getting distracted by providing customised examples for people or getting into side

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

2018-07-23 Thread Steve Dower
On 23Jul2018 0151, Steven D'Aprano wrote: What if there was a language supported, non-hackish way to officially delay evaluation of expressions until explicitly requested? The current spelling for this is "lambda: delayed-expression" and the way to request the value is "()". :) (I'm not even

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

2018-07-23 Thread Grégory Lielens
On Monday, July 23, 2018 at 8:24:45 AM UTC+2, Nicholas Cole wrote: And that leads to a simple question: how many times does this actually > occur in real-world by python code? -- i.e. how many times do I want > to check the value of an existing label, and, finding it is None (and > None speci

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

2018-07-22 Thread Nicholas Cole
On Mon, Jul 23, 2018 at 2:38 AM Steven D'Aprano wrote: > > On Mon, Jul 23, 2018 at 12:59:20AM +0200, Giampaolo Rodola' wrote: > > > You're back at "since we have X that justifies the addition of Y" [1] > > and AFAICT that's the only argument you have provided so far in a 100+ > > messages discussi

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

2018-07-22 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 12:59:20AM +0200, Giampaolo Rodola' wrote: > You're back at "since we have X that justifies the addition of Y" [1] > and AFAICT that's the only argument you have provided so far in a 100+ > messages discussion. The PEP itself justifies the addition of Y. Chris' argument,

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

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 05:09:39PM +0200, Giampaolo Rodola' wrote: > > > I personally don't find "a ?? b" too bad (let's say I'm -0 about it) > > > but idioms such as "a?.b", "a ??= b" and "a?[3] ?? 4" look too > > > Perl-ish to me, non pythonic and overall not explicit, no matter what > > > the c

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

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 11:26:15PM +1000, Chris Angelico wrote: > You forget that the operator will *short-circuit*. It will not > evaluate the second argument if the first argument is None. You cannot > do this with a function, other than with a hack like a lambda > function. We keep running up

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

2018-07-22 Thread Giampaolo Rodola'
On Mon, Jul 23, 2018 at 12:08 AM Chris Angelico wrote: > > On Mon, Jul 23, 2018 at 7:51 AM, Giampaolo Rodola' wrote: > > On Sun, Jul 22, 2018 at 10:55 PM Chris Angelico wrote: > >> > >> On Mon, Jul 23, 2018 at 6:43 AM, Giampaolo Rodola' > >> wrote: > >> > On Sun, Jul 22, 2018 at 10:01 PM Chris

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

2018-07-22 Thread Chris Angelico
On Mon, Jul 23, 2018 at 7:51 AM, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 10:55 PM Chris Angelico wrote: >> >> On Mon, Jul 23, 2018 at 6:43 AM, Giampaolo Rodola' >> wrote: >> > On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: >> >> >> >> On Mon, Jul 23, 2018 at 1:09 AM, Giampao

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 10:55 PM Chris Angelico wrote: > > On Mon, Jul 23, 2018 at 6:43 AM, Giampaolo Rodola' wrote: > > On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: > >> > >> On Mon, Jul 23, 2018 at 1:09 AM, Giampaolo Rodola' > >> wrote: > >> > On Sun, Jul 22, 2018 at 3:38 PM Chris

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 11:51 PM Giampaolo Rodola' wrote: > > On Sun, Jul 22, 2018 at 10:55 PM Chris Angelico wrote: > > > > On Mon, Jul 23, 2018 at 6:43 AM, Giampaolo Rodola' > > wrote: > > > On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: > > >> > > >> On Mon, Jul 23, 2018 at 1:09 AM,

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

2018-07-22 Thread David Mertz
On Sun, Jul 22, 2018, 4:56 PM Chris Angelico wrote: > It means people place crazily high demands on new proposals. > I think the bar has been much too low for introducing new features over the last 5 years or so. Internal changes like the new dictionary implementation are fine, but user-facing c

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

2018-07-22 Thread Antoine Pitrou
On Mon, 23 Jul 2018 06:53:53 +1000 Chris Angelico wrote: > > >> Which is back to what Steven said: people demand such a high > >> bar for new syntax that few existing pieces of syntax would pass it. > > > > Probably. That's what happens when a language is mature. Personally I > > don't think th

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

2018-07-22 Thread Peter J. Holzer
On 2018-07-22 10:33:23 -0700, Michael Selik wrote: > On Sat, Jul 21, 2018, 6:55 PM Steven D'Aprano wrote: > On Sun, Jul 22, 2018 at 01:56:35AM +0200, Giampaolo Rodola' wrote: > > On Thu, Jul 19, 2018 at 3:39 PM Steven D'Aprano > > wrote: > > > Tens of thousands of non-English spea

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

2018-07-22 Thread Chris Angelico
On Mon, Jul 23, 2018 at 6:43 AM, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: >> >> On Mon, Jul 23, 2018 at 1:09 AM, Giampaolo Rodola' >> wrote: >> > On Sun, Jul 22, 2018 at 3:38 PM Chris Angelico wrote: >> > I find it less explicit mainly because it does 3

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

2018-07-22 Thread Antoine Pitrou
On Sun, 22 Jul 2018 22:43:15 +0200 "Giampaolo Rodola'" wrote: > On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: > > > > On Mon, Jul 23, 2018 at 1:09 AM, Giampaolo Rodola' > > wrote: > > > On Sun, Jul 22, 2018 at 3:38 PM Chris Angelico wrote: > > > I find it less explicit mainly becau

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 10:01 PM Chris Angelico wrote: > > On Mon, Jul 23, 2018 at 1:09 AM, Giampaolo Rodola' wrote: > > On Sun, Jul 22, 2018 at 3:38 PM Chris Angelico wrote: > > I find it less explicit mainly because it does 3 things at once: check > > if attribute is None, use it if it's not N

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

2018-07-22 Thread Chris Angelico
On Mon, Jul 23, 2018 at 1:09 AM, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 3:38 PM Chris Angelico wrote: >> >> On Sun, Jul 22, 2018 at 11:35 PM, Giampaolo Rodola' >> wrote: >> > On Sun, Jul 22, 2018 at 2:10 PM Steven D'Aprano >> > wrote: >> >> >> >> On Sun, Jul 22, 2018 at 12:13:04PM

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

2018-07-22 Thread Clément Pit-Claudel
On 2018-07-22 08:10, Steven D'Aprano wrote: > Indeed. And I think we ought to think carefully about the benefits and > costs of all of those variants separately. > > To me, the ?? operator seems like a clear and obvious win. The other > variants are more complex and the benefit is not as obvious

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

2018-07-22 Thread Michael Selik
On Sat, Jul 21, 2018, 6:55 PM Steven D'Aprano wrote: > On Sun, Jul 22, 2018 at 01:56:35AM +0200, Giampaolo Rodola' wrote: > > On Thu, Jul 19, 2018 at 3:39 PM Steven D'Aprano > wrote: > > > Tens of thousands of non-English speakers have had to learn the meaning > > > of what might as well be mean

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

2018-07-22 Thread Peter J. Holzer
On 2018-07-22 09:01:58 -0400, David Mertz wrote: > On Sun, Jul 22, 2018, 8:11 AM Steven D'Aprano wrote: > To me, the ?? operator seems like a clear and obvious win. The other > variants are more complex and the benefit is not as obvious to me, so I > haven't decided where I stand on th

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 3:38 PM Chris Angelico wrote: > > On Sun, Jul 22, 2018 at 11:35 PM, Giampaolo Rodola' > wrote: > > On Sun, Jul 22, 2018 at 2:10 PM Steven D'Aprano wrote: > >> > >> On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: > >> > On Sun, Jul 22, 2018 at 3:55 AM S

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

2018-07-22 Thread Stephen J. Turnbull
Steven D'Aprano writes: > In my opinion, writing > > expression if expression is None else default > > is the *opposite* of Pythonic, it is verbose and the DRY violation is > inelegant (as well as inefficient). I'd much rather use: > > expression ?? default Sure, if "expressio

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

2018-07-22 Thread Grégory Lielens
Short circuit if the first argument is NOT None, I guess? ;-) Yes, so a short circuit is sometimes good. Not often imho, for a default triggered by None, but sometimes... In the case it is, do you want it to be hidden in an expression? Usually it would be better to draw attention, when the defau

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

2018-07-22 Thread Chris Angelico
On Sun, Jul 22, 2018 at 11:35 PM, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 2:10 PM Steven D'Aprano wrote: >> >> On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: >> > On Sun, Jul 22, 2018 at 3:55 AM Steven D'Aprano >> > wrote: >> [...] >> > > I don't think that "+" is

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 2:10 PM Steven D'Aprano wrote: > > On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: > > On Sun, Jul 22, 2018 at 3:55 AM Steven D'Aprano wrote: > [...] > > > I don't think that "+" is harder to read than > > > "standard_mathematics_operators_numeric_additi

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

2018-07-22 Thread Chris Angelico
On Sun, Jul 22, 2018 at 11:22 PM, Grégory Lielens wrote: > The ?? operator is probably the less scary one regarding legibility, and in > guessing (or remembering) what it exactly does... > Well, at least I think I understand what it does exactly, but if I'm not > wrong there, what it does is als

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

2018-07-22 Thread Grégory Lielens
The ?? operator is probably the less scary one regarding legibility, and in guessing (or remembering) what it exactly does... Well, at least I think I understand what it does exactly, but if I'm not wrong there, what it does is also quite simple and minimal. A function returning it's first non-N

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

2018-07-22 Thread David Mertz
On Sun, Jul 22, 2018, 8:11 AM Steven D'Aprano wrote: > On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: > > Please let's drop the argument that + - * / = and ? are the same. > We shouldn't judge proposals on how mysterious they are the first time we > see them, because everythin

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

2018-07-22 Thread Chris Angelico
On Sun, Jul 22, 2018 at 10:10 PM, Steven D'Aprano wrote: > As a community, we're risk-adverse. I understand why we should be > conservative in what we add to the language (once added, it cannot > easily be removed if it turns out to be a mistake) but on Python-Ideas > we regularly demand levels of

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

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 3:55 AM Steven D'Aprano wrote: [...] > > I don't think that "+" is harder to read than > > "standard_mathematics_operators_numeric_addition" > > > Please let's drop the argument that + - * / = and ? are

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

2018-07-22 Thread Grégory Lielens
Except that the third possibility is not possible...if a is None, a[2] will throw an exception... For now at least ;-) ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://pyt

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 12:26 PM Paul Moore wrote: > On 22 July 2018 at 11:13, Giampaolo Rodola' wrote: > > - "a?[2] ?? 3" means "index 2 of list a is picked up if a is not None, > else > > use 3" > > Actually, doesn't it mean > > if a is not None, pick up index 2 of the list. > If a is None, OR

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

2018-07-22 Thread Paul Moore
On 22 July 2018 at 11:13, Giampaolo Rodola' wrote: > - "a?[2] ?? 3" means "index 2 of list a is picked up if a is not None, else > use 3" Actually, doesn't it mean if a is not None, pick up index 2 of the list. If a is None, OR IF a[2] IS NONE, then use 3. If a is None but a[2] is not None, use

<    1   2   3   4   >