Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-30 Thread Steven D'Aprano
On Sun, Oct 30, 2016 at 06:26:13AM -0700, David Mertz wrote: > NaN's *usually* propagate. The NaN domain isn't actually closed under IEEE > 754. [...] > >>> min(1, nan) > 1 > > The last one isn't really mandated by IEEE 754, and is weird when you > consider `min(nan, 1)`. Python's min() and ma

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-30 Thread David Mertz
On Sat, Oct 29, 2016 at 11:44 PM, Stephan Hoyer wrote: > I'm have more mixed fillings on testing for NaNs. NaNs propagate, so > explicit testing is rarely needed. Also, in numerical computing we usually > work with arrays of NaN, so operator.exists() and all this nice syntax > would not be a subs

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Stephan Hoyer
On Sat, Oct 29, 2016 at 3:53 AM, Steven D'Aprano wrote: > Hmmm. I see your point, but honestly, None *is* special. Even for > special objects, None is even more special. As a contributor to and user of many numerical computing libraries in Python (e.g., NumPy, pandas, Dask, TensorFlow) I also a

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Nick Coghlan
On 29 October 2016 at 21:44, Steven D'Aprano wrote: > On Fri, Oct 28, 2016 at 06:30:05PM +1000, Nick Coghlan wrote: > > [...] >> 1. Do we collectively agree that "existence checking" is a useful >> general concept that exists in software development and is distinct >> from the concept of "truth ch

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Ryan Gonzalez
On Oct 28, 2016 3:30 AM, "Nick Coghlan" wrote: > *snip* > > 1. Do we collectively agree that "existence checking" is a useful > general concept that exists in software development and is distinct > from the concept of "truth checking"? I'd hope so! > 2. Do we collectively agree that the Python e

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Ryan Birmingham
I certainly like the concept, but I worry that use of __exists__() could generalize it a bit beyond what you're intending in practice. It seems like this should only check if an object exists, and that adding the magic method would only lead to confusion. -Ryan Birmingham On 28 October 2016 at 0

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Steven D'Aprano
On Fri, Oct 28, 2016 at 06:30:05PM +1000, Nick Coghlan wrote: [...] > 1. Do we collectively agree that "existence checking" is a useful > general concept that exists in software development and is distinct > from the concept of "truth checking"? Not speaking for "we", only for myself: of course.

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Steven D'Aprano
On Sat, Oct 29, 2016 at 02:52:42PM +1000, Nick Coghlan wrote: > On 29 October 2016 at 04:08, Mark Dickinson wrote: > > On Fri, Oct 28, 2016 at 9:30 AM, Nick Coghlan wrote: > >> [...] the current practicises of: > >> > >> * obj is not None (many different use cases) > >> * obj is not Ellipsis (in

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Steven D'Aprano
On Sat, Oct 29, 2016 at 03:03:22PM +1000, Nick Coghlan wrote: > On 29 October 2016 at 01:46, Ryan Gonzalez wrote: > > On Oct 28, 2016 3:30 AM, "Nick Coghlan" wrote: > >> *snip* > >> 4. Do we collectively agree that "?then" and "?else" would be > >> reasonable spellings for such operators? > > > >

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-29 Thread Paul Moore
On 29 October 2016 at 07:21, Nick Coghlan wrote: > A short-circuiting if-else protocol for arbitrary "THEN if COND else > ELSE" expressions could then look like this: > > _condition = COND > if _condition: > _then = THEN > if hasattr(_condition, "__then__"): > r

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Nick Coghlan
On 29 October 2016 at 14:52, Nick Coghlan wrote: > And that reflects the problem Paul and David highlighted: in any > *specific* context, there's typically either only one sentinel we want > to either propagate or else replace with a calculated value, or else > we want to handle different sentinel

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Nick Coghlan
On 29 October 2016 at 01:46, Ryan Gonzalez wrote: > On Oct 28, 2016 3:30 AM, "Nick Coghlan" wrote: >> *snip* >> 4. Do we collectively agree that "?then" and "?else" would be >> reasonable spellings for such operators? > > Personally, I find that kind of ugly. What's wrong with just ? instead of >

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Nick Coghlan
On 29 October 2016 at 04:08, Mark Dickinson wrote: > On Fri, Oct 28, 2016 at 9:30 AM, Nick Coghlan wrote: >> [...] the current practicises of: >> >> * obj is not None (many different use cases) >> * obj is not Ellipsis (in multi-dimensional slicing) > > Can you elaborate on this one? I don't thin

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Sven R. Kunze
Hi Nick, thanks for writing all of this down and composing a PEP. On 28.10.2016 10:30, Nick Coghlan wrote: 1. Do we collectively agree that "existence checking" is a useful general concept that exists in software development and is distinct from the concept of "truth checking"? Right to your

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Mark Dickinson
On Fri, Oct 28, 2016 at 9:30 AM, Nick Coghlan wrote: > [...] the current practicises of: > > * obj is not None (many different use cases) > * obj is not Ellipsis (in multi-dimensional slicing) Can you elaborate on this one? I don't think I've ever seen an `is not Ellipsis` check in real code. --

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread David Mertz
On Fri, Oct 28, 2016 at 11:17 AM, Paul Moore wrote: > On 28 October 2016 at 15:40, Nick Coghlan wrote: > > I also don't think the idea is sufficiently general to be worthy of > > dedicated syntax if it's limited specifically to "is not None" checks > > - None's definitely special, but it's not *

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Paul Moore
On 28 October 2016 at 15:40, Nick Coghlan wrote: > I also don't think the idea is sufficiently general to be worthy of > dedicated syntax if it's limited specifically to "is not None" checks > - None's definitely special, but it's not *that* special. Unifying > None, NaN, NotImplemented and Ellips

Re: [Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Nick Coghlan
On 28 October 2016 at 23:35, Ryan Birmingham wrote: > I certainly like the concept, but I worry that use of __exists__() could > generalize it a bit beyond what you're intending in practice. It seems like > this should only check if an object exists, and that adding the magic method > would only

[Python-ideas] PEP 531: Existence checking operators

2016-10-28 Thread Nick Coghlan
Hi folks, After the recent discussions of PEP 505's null-coalescing operator (and the significant confusion around why anyone would ever want a feature like that), I was inspired to put together a competing proposal that focuses more on defining a new "existence checking" protocol that generalises