Skip to content

Commit

Permalink
Drop useless __nonzero__
Browse files Browse the repository at this point in the history
Python uses (x.__len__() != 0) to implement bool(x) when x doesn't
define a __nonzero__ (__bool__ on Pyton 3).

Add tests to make sure this works.
  • Loading branch information
mgedmin committed Jun 5, 2016
1 parent d701d22 commit de2c083
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/z3c/batching/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Batch on empty root:
>>> batch = Batch([], size=3)
>>> len(batch)
0
>>> bool(batch)
False
>>> batch.firstElement
Traceback (most recent call last):
...
Expand Down Expand Up @@ -75,6 +77,11 @@ for:
>>> len(Batch(sequence, start=12, size=3))
1

Like any sequence, a non-empty batch is true-ish in a boolean context:

>>> bool(batch)
True

You can also get an element by index, which is relative to the batch:

>>> batch[0]
Expand Down
5 changes: 0 additions & 5 deletions src/z3c/batching/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

def __nonzero__(self):
return self._trueSize != 0

# XXX __bool__ on py3!

def __repr__(self):
return '<%s start=%i, size=%i>' % (
self.__class__.__name__, self.start, self.size)
Expand Down

0 comments on commit de2c083

Please sign in to comment.