Commit c649bfc8 authored by Kipp Cannon's avatar Kipp Cannon
Browse files

various aesthetic changes

parent 33567a28
...@@ -107,7 +107,7 @@ class infinity(object): ...@@ -107,7 +107,7 @@ class infinity(object):
>>> math.isinf(x) >>> math.isinf(x)
True True
""" """
__slots__ = [] __slots__ = ()
def __new__(cls, *args): def __new__(cls, *args):
if args: if args:
...@@ -124,9 +124,7 @@ class infinity(object): ...@@ -124,9 +124,7 @@ class infinity(object):
""" """
Returns a string. Returns a string.
""" """
if self is PosInfinity: return "infinity" if self is PosInfinity else "-infinity"
return "infinity"
return "-infinity"
__str__ = __repr__ __str__ = __repr__
...@@ -136,10 +134,7 @@ class infinity(object): ...@@ -136,10 +134,7 @@ class infinity(object):
""" """
Pickle support. Pickle support.
""" """
if self is PosInfinity: return infinity, ((1,) if self is PosInfinity else (-1,))
return (infinity, (1,))
# self is NegInfinity
return (infinity, (-1,))
# tests # tests
...@@ -173,10 +168,7 @@ class infinity(object): ...@@ -173,10 +168,7 @@ class infinity(object):
""" """
Returns -self. Returns -self.
""" """
if self is PosInfinity: return NegInfinity if self is PosInfinity else PosInfinity
return NegInfinity
# self is NegInfinity
return PosInfinity
def __pos__(self): def __pos__(self):
""" """
...@@ -206,19 +198,13 @@ class infinity(object): ...@@ -206,19 +198,13 @@ class infinity(object):
""" """
Returns -self. Returns -self.
""" """
if self is PosInfinity: return NegInfinity if self is PosInfinity else PosInfinity
return NegInfinity
# self is NegInfinity
return PosInfinity
def __float__(self): def __float__(self):
""" """
Returns +/-inf (allows math.isinf() to work). Returns +/-inf (allows math.isinf() to work).
""" """
if self is PosInfinity: return float("+inf") if self is PosInfinity else float("-inf")
return float("+inf")
# self is NegInfinity
return float("-inf")
PosInfinity = object.__new__(infinity) PosInfinity = object.__new__(infinity)
...@@ -462,8 +448,7 @@ class segment(tuple): ...@@ -462,8 +448,7 @@ class segment(tuple):
a, b = other a, b = other
except (ValueError, TypeError): except (ValueError, TypeError):
return self[0] <= other < self[1] return self[0] <= other < self[1]
else: return (self[0] <= a) and (self[1] >= b)
return (self[0] <= a) and (self[1] >= b)
# protraction and contraction and shifting # protraction and contraction and shifting
...@@ -580,13 +565,13 @@ class segmentlist(list): ...@@ -580,13 +565,13 @@ class segmentlist(list):
""" """
if not len(self): if not len(self):
raise ValueError("empty list") raise ValueError("empty list")
min, max = self[0] mn, mx = self[0]
for lo, hi in self: for lo, hi in self:
if min > lo: if mn > lo:
min = lo mn = lo
if max < hi: if mx < hi:
max = hi mx = hi
return segment(min, max) return segment(mn, mx)
def find(self, item): def find(self, item):
""" """
......
Supports Markdown
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