On Thu, Nov 13, 2014 at 8:24 AM, Alan G Isaac alan.is...@gmail.com wrote:
On 11/13/2014 1:19 AM, Antony Lee wrote:
t.__bool__() also returns True
But t.__nonzero__() is being called in the `if` test.
The question is: is the difference between `__nonzero__`
and `__bool__` intentional.
By
On Mi, 2014-11-12 at 22:19 -0800, Antony Lee wrote:
I know you can't in general, but this was in a context where I knew
the array contained a single element, which works (it checks the
truthiness of the contained element). Of course I didn't consider the
case where the element contained was
On 11/13/2014 1:19 AM, Antony Lee wrote:
t.__bool__() also returns True
But t.__nonzero__() is being called in the `if` test.
The question is: is the difference between `__nonzero__`
and `__bool__` intentional.
By the way, there has been a change in behavior.
For example, in 1.7.1 if you call
On Do, 2014-11-13 at 08:24 -0500, Alan G Isaac wrote:
On 11/13/2014 1:19 AM, Antony Lee wrote:
t.__bool__() also returns True
But t.__nonzero__() is being called in the `if` test.
The question is: is the difference between `__nonzero__`
and `__bool__` intentional.
By the way, there
On Python3, __nonzero__ is never defined (always raises an AttributeError),
even after calling __bool__.
2014-11-13 5:24 GMT-08:00 Alan G Isaac alan.is...@gmail.com:
On 11/13/2014 1:19 AM, Antony Lee wrote:
t.__bool__() also returns True
But t.__nonzero__() is being called in the `if`
On 11/13/2014 12:37 PM, Antony Lee wrote:
On Python3, __nonzero__ is never defined (always raises an AttributeError),
even after calling __bool__.
The example I posted was Python 3.4.1 with numpy 1.9.0.
fwiw,
Alan Isaac
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600
Dunno, seems unlikely that something changed with Python 3.4.2...
$ python --version
Python 3.4.2
$ python -c 'import numpy as np; print(np.__version__); t = np.array(None);
t[()] = np.array([None, None]); t.__bool__(); t.__nonzero__()'
1.9.0
Traceback (most recent call last):
File string, line
On Thu, Nov 13, 2014 at 1:24 PM, Alan G Isaac alan.is...@gmail.com wrote:
On 11/13/2014 1:19 AM, Antony Lee wrote:
t.__bool__() also returns True
But t.__nonzero__() is being called in the `if` test.
The question is: is the difference between `__nonzero__`
and `__bool__` intentional.
On 11/13/2014 1:32 PM, Nathaniel Smith wrote:
I think you're being misled by buggy exception handling weirdness,
where the ValueError raised by calling __bool__ is getting delayed,
and then pre-empting the AttributeError that should be generated by
the call to __nonzero__.
Aha!
Thanks.
I am puzzled by the following (numpy 1.9.0, python 3.4.2):
In [1]: t = array(None); t[()] = array([None, None]) # Construct a 0d
array of dtype object, containing a single numpy array with 2 elements
In [2]: bool(t)
Out[2]: True
In [3]: if t: pass
10 matches
Mail list logo