Commit 09a416da authored by Kipp Cannon's avatar Kipp Cannon

Merge branch 'python3-bool' into 'master'

Renamed __nonzero__ to __bool__ for python3

See merge request !20
parents 5bec579d 6793487f
Pipeline #58979 failed with stages
in 10 minutes and 52 seconds
......@@ -10,6 +10,7 @@ stages:
- python -m pip install setuptools
script:
- python -m pip install .
- python -m pip install lalsuite # for lal
- make -C test
test:2.7:
......
......@@ -41,7 +41,7 @@ See also:
ligo.segments.utils
"""
import sys
from bisect import bisect_left
from bisect import bisect_right
from copy import copy as shallowcopy
......@@ -156,11 +156,18 @@ class infinity(object):
def __ne__(self, other):
return self is not other
def __nonzero__(self):
"""
Returns True.
"""
return True
if sys.version_info.major < 3:
def __nonzero__(self):
"""
Returns True.
"""
return True
else:
def __bool__(self):
"""
Returns True.
"""
return True
# arithmetic
......@@ -315,12 +322,20 @@ class segment(tuple):
# comparisons
def __nonzero__(self):
"""
Return True if the segment's boudaries are not equal, False
if they are equal.
"""
return self[0] != self[1]
if sys.version_info.major < 3:
def __nonzero__(self):
"""
Return True if the segment's boudaries are not equal, False
if they are equal.
"""
return self[0] != self[1]
else:
def __bool__(self):
"""
Return True if the segment's boudaries are not equal, False
if they are equal.
"""
return self[0] != self[1]
def disjoint(self, other):
"""
......
......@@ -19,6 +19,8 @@ try:
import builtins
except ImportError:
import __builtin__ as builtins
else:
from importlib import reload
realimport = builtins.__import__
......@@ -559,12 +561,12 @@ if __name__ == "__main__":
# then with C extension implementation
from ligo.segments import __segments
segments.infinity = __segments.infinity
segments.NegInfinity = __segments.NegInfinity
segments.PosInfinity = __segments.PosInfinity
segments.segment = __segments.segment
segments.segmentlist = __segments.segmentlist
reload(segments) # loads C library and executes copyreg.pickle
segments.infinity = segments.infinity
segments.NegInfinity = segments.NegInfinity
segments.PosInfinity = segments.PosInfinity
segments.segment = segments.segment
segments.segmentlist = segments.segmentlist
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_infinity))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment