Maintenance will be performed on,,, and on Tuesday 7th July 2020 starting at approximately 10am PDT and lasting for around 15 minutes. There will be a short period of downtime towards the end of the maintenance window. Please direct any comments, questions, or concerns to

Commit c10574d4 authored by Kipp Cannon's avatar Kipp Cannon

in Python version be careful of len() vs bool()

- don't rely on bool(other) testing that other is an empty sequence, or else operations like segmentlist() - None appear to work.  The C version already does this correctly.
parent 790e11d2
......@@ -676,7 +676,10 @@ class segmentlist(list):
and another. For lists of length m and n respectively,
this operation is O(n + m).
if not other:
# we test len() and not simply bool() to not allow
# arithmetic to succeed on objects simply because they are
# logically false
if not len(other):
return self
if other is self:
del self[:]
......@@ -748,8 +751,11 @@ class segmentlist(list):
calculation of the intersection, i.e. by testing bool(self
& other). Requires both lists to be coalesced.
# if either has zero length, the answer is False
if not (self and other):
# if either has zero length, the answer is False. we know
# our bool() tests our length, but we use len() on other
# explicitly to avoid allowing arithmetic to succeed on
# objects simply because their boolean falue is false
if not (self and len(other)):
return False
# walk through both lists in order, searching for a match
i = j = 0
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment