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

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

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

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

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

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

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

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,

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

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

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

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

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 <

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"?

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

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

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

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

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

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?

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: [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

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

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:

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

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

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 >

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

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

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

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

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

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

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

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

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

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

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

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

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

2018-07-23 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

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

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

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,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 "+"

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

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

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

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

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:

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,

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

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

2018-07-22 Thread Giampaolo Rodola'
On Sun, Jul 22, 2018 at 3:55 AM Steven D'Aprano wrote: > Indeed we do. But we also say: > > - we say "+" instead of "add" > - we say "//" instead of "floor division" > - we say "**" instead of "exponentiation" > - we say "&" instead of "bitwise AND" > - we say "f( ... )" instead of "call f with

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

2018-07-22 Thread Grégory Lielens
To get rid of the two other ( ?. And ?[] ), we could also define getitem and getattr for None to always return None...;-) I'm joking, although such an "absorbing" None may have been a good choice when None was introduced, and maybe a way to do an absorbing-None per-statement maybe nice...Nice

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

2018-07-22 Thread Paul Moore
On 22 July 2018 at 02:54, Steven D'Aprano wrote: > I'll admit that the number and variety of new operators gives me some > reason to pause, but for the simplest and most obvious case, the > proposed ?? operator, I think that the fears about readability are > grossly exaggerated. Certainly *my*

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

2018-07-21 Thread Chris Angelico
On Sun, Jul 22, 2018 at 11:54 AM, Steven D'Aprano wrote: > If we gained a function > or even a keyword from Italian, let's say "ripetere", would that really > change the nature of Python? I don't think so. English speakers are > adaptable, we don't so much borrow words from other languages as

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

2018-07-21 Thread Steven D'Aprano
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 meaningless, random sets of symbols (to them) > > like "class",

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

2018-07-21 Thread Giampaolo Rodola'
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 meaningless, random sets of symbols (to them) > like "class", "import", "while" and "True". If they can do so, perhaps > we English-speakers

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

2018-07-21 Thread Ivan Levkivskyi
I think I am with Michael here. I like the parallel between `??` and `or`, we don't have `or=`, so `??=` is also not needed. Although I understand a parallel between `obj.attr` and `obj['attr']`, I think there is an additional point (in addition to two valid points by Michael) why I don't like

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

2018-07-20 Thread Steve Dower
On 20Jul2018 1119, Brendan Barnwell wrote: In this situation I lean toward "explicit is better than implicit" --- if you want to compare against None, you should do so explicitly --- and "special cases aren't special enough to break the rules" --- that is, None is not special enough to warrant

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

2018-07-20 Thread Brendan Barnwell
On 2018-07-20 10:52, Steven D'Aprano wrote: The problem is that `A else B` looks like it ought to be the same as "else B" in if...else statements and the ternary if operator. That is, "if the condition is false", and in this case there is nothing that even hints that the condition is "A is None"

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

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 12:03:47PM +1200, Greg Ewing wrote: > Rhodri James wrote: > >If anyone can think of a good word for "if it isn't None, otherwise", > >I'd be all for it :-) > > I don't think there's any single Engish word that captures > all of that, so we'd have to invent one. > > Some

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

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 10:33:21AM +0200, Antoine Pitrou wrote: > def insort_right(a, x, lo=0, hi=None): > # ... > hi = hi else len(a) I read that as "hi, if it is truthy, else len(a)". The advantage of ?? as None-aware operator is that it cannot possibly be misread as

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

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 08:57:50PM -0400, Michael Selik wrote: > Try/except also looks decent. > > try: > x = foo['bar'][0] > except TypeError: > x = 'default' Consider the case that foo['bar'] is supposed to return either a collection (something that can be indexed) or

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

2018-07-20 Thread Mark E. Haase
On Thu, Jul 19, 2018 at 2:36 PM Brendan Barnwell wrote: > People keep saying that this null-coalescing behavior is so common > and > useful, etc., but that hasn't been my experience at all. In my > experience, the desire to shortcut this kind of logic is more often a > sign of

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

2018-07-20 Thread Steve Dower
Just for fun, I decided to go through some recently written code by some genuine Python experts (without their permission...) to see what changes would be worth taking. So I went to the sources of our github bots. Honestly, I only found three places that were worth changing (though I'm now

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

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 12:57:01PM +0100, Jonathan Fine 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 [...] > > Perhaps

<    1   2   3   >