Re: [Python-ideas] A better (simpler) approach to PEP 505

2018-07-24 Thread Grégory Lielens
Interesting, looking into, let's say, 100 of those is [not] None, randomly chosen, should give an very good idea of typical use for your code base. I am curious about why you don't like solutions involving exceptions? Performance? Catching too much, like typing errors? Less easy to distinguish

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-24 Thread Jonathan Fine
Here's another way that None is special. === >>> NoneType = type(None) >>> >>> class myNoneType(NoneType): pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'NoneType' is not an acceptable base type === For more information see

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] A better (simpler) approach to PEP 505

2018-07-24 Thread Giampaolo Rodola'
On Tue, Jul 24, 2018 at 1:57 AM Stefan Behnel wrote: > > David Mertz schrieb am 23.07.2018 um 16:12: > > The need addressed by PEP 505 is real; it's also MUCH more niche and > > uncommon than something that would merit new syntax. Moreover, the actual > > legitimate purpose served by the PEP 505

Re: [Python-ideas] Idea: Deferred Default Arguments?

2018-07-24 Thread Kyle Lahnakoski
I agree this is a problem, which I have seen solved by removing the method signature, which is unfortunate: > def flexible_method(**kwargs): >     # Read the code to find out the expected parameters    I have an @override decorator to handle this type of pattern. It will perform the

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

[Python-ideas] Fwd: A better (simpler) approach to PEP 505

2018-07-24 Thread David Mertz
I started a new thread where I show a small library I made yesterday that ALSO matches 505 semantics, as well as more general AttributeError swallowing. It has two classes with sightly different behavior. So we don't need syntax for either semantics. On Tue, Jul 24, 2018, 3:29 AM Grégory Lielens

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] A better (simpler) approach to PEP 505

2018-07-24 Thread Grégory Lielens
On Tuesday, July 24, 2018 at 2:39:19 AM UTC+2, Steven D'Aprano wrote: > PEP 505 has a section explaining why catching AttributeError > is undesirable. I find the reasons it gives are compelling. > > Can you explain why you reject the PEP's arguments against catching > AttributeError? > >

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 <