[issue43786] slice(None) is slice(None) is False

2021-04-09 Thread Nico Schlömer

Nico Schlömer  added the comment:

Thanks very much, Steven, for the feedback and the suggestion.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43786] slice(None) is slice(None) is False

2021-04-09 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

The behaviour of `is` is correct.

The `is` operator tests for object identity, not equality. The reason that 
`slice(None) is slice(None)` returns False is that the two calls to the slice 
function return two different objects.

You say that using the equals operator `==` "doesn't return a single Boolean if 
a is a NumPy array", that is a design flaw in numpy, and there is nothing we 
can do about it.

You could try something like this:

def equal(a, b):
flag = (a == b)
if isinstance(flag, bool):
return flag
else:
return all(flag)

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43786] slice(None) is slice(None) is False

2021-04-09 Thread Nico Schlömer

New submission from Nico Schlömer :

I stumbled upon this when dealing with NumPy arrays:
```
slice(None) is slice(None)
```
```
False
```
This came up when trying to check if a variable `a` equals `slice(None)`. The 
comparison
```
a = slice(None)
a == slice(None)
```
```
True
```
works, but doesn't return a single Boolean if a is a NumPy array, for example.

Perhaps there's another way of finding out if a variable is exactly 
`slice(None)`, but the failure of `is` seems like a bug.

--
messages: 390598
nosy: nschloe
priority: normal
severity: normal
status: open
title: slice(None) is slice(None) is False

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com