Skip to content

Commit

Permalink
gc3libs.utils.PlusInfinity: support adding and subtracting a (finite)…
Browse files Browse the repository at this point in the history
… number.
  • Loading branch information
riccardomurri committed May 8, 2018
1 parent 24aacca commit cc1b4ff
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gc3libs/utils.py
Expand Up @@ -1825,6 +1825,16 @@ class PlusInfinity(Singleton):
>>> x > y
False
Finally, addition and subtraction of a finite number from
`PlusInfinity` always results in `PlusInfinity`::
>>> y = x - 1
>>> x == y
True
>>> y = x + 1
>>> x == y
True
"""

def __gt__(self, other):
Expand Down Expand Up @@ -1854,6 +1864,15 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

def __add__(self, other):
return self

def __sub__(self, other):
if other == self:
raise RuntimeError(
"Undefined result subtracting +infinity from +infinity.")
return self


# In Python 2.7 still, `DictMixin` is an old-style class; thus, we need
# to make `Struct` inherit from `object` otherwise we loose properties
Expand Down

0 comments on commit cc1b4ff

Please sign in to comment.