2to3: Apply nonzero fixer. #3241

Merged
merged 1 commit into from Apr 14, 2013

Projects

None yet

2 participants

@charris
Member
charris commented Apr 13, 2013

In Python 3 the __nonzero__ class method is replaced by __bool__.
This only affects the MaskedArray class in numpy/oldnumeric/ma.py file
and the simplest solution is to provide both methods. I have my doubts
that the fixed up Python 3 version was correct or even tested, but I
think the current solution should work for as long as oldnumeric stays
in numpy.

Closes #3073.

@charris charris 2to3: Apply nonzero fixer.
In Python 3 the `__nonzero__` class method is replaced by `__bool__`.
This only affects the MaskedArray class in numpy/oldnumeric/ma.py file
and the simplest solution is to provide both methods. I have my doubts
that the fixed up Python 3 version was correct or even tested, but I
think the current solution should work for as long as oldnumeric stays
in numpy.

Closes #3073.
54ca3f2
@charris
Member
charris commented Apr 14, 2013

Still looks good in the morning. This is a minimal change that adds a method expected by Python 3. 2to3 would just rename the nonzero method, so the copy here should have the same result.

@charris charris merged commit 61c5ac6 into numpy:master Apr 14, 2013

1 check passed

default The Travis build passed
Details
@charris charris deleted the charris:2to3-apply-nonzero-fixer branch Apr 14, 2013
@njsmith
Member
njsmith commented Apr 14, 2013

Better than copy/pasting the code would be to call nonzero or just write

bool = nonzero

Not a big deal though.
On 14 Apr 2013 15:34, "Charles Harris" notifications@github.com wrote:

Still looks good in the morning. This is a minimal change that adds a
method expected by Python 3. 2to3 would just rename the nonzero method,
so the copy here should have the same result.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/pull/3241#issuecomment-16351942
.

@charris
Member
charris commented Apr 14, 2013

Heh, yeah. I did consider it, but copy paste was less work ;) Plus if we ever drop 2.7, say in ten years of so, and this module is still around, we can erase nonzero.

@njsmith
Member
njsmith commented Apr 15, 2013

Sure. And I guess it's not too likely they'll diverge given that no-one
works on np.ma...

On Sun, Apr 14, 2013 at 10:42 PM, Charles Harris
notifications@github.comwrote:

Heh, yeah. I did consider it, but copy paste was less work ;) Plus if we
ever drop 2.7, say in ten years of so, and this module is still around, we
can erase nonzero.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/pull/3241#issuecomment-16360183
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment