Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Z. D. Smith committed May 28, 2014
0 parents commit 13ccce4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Empty file added __init__.py
Empty file.
25 changes: 25 additions & 0 deletions nonzero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Certain types of numerical values don't understand the concept of 0, usually ordinal
Values: years, streets, storeys.
"""

class nz(int):
def check_for_0(s):
def f(self, other):
method = getattr(super(), s)
if self < 0 and method(other) >= 0:
return type(self)(method(other) + 1)
elif self > 0 and method(other) <= 0:
return type(self)(method(other) - 1)
else:
return type(self)(method(other))
return f

def __new__(cls, x):
if x == 0:
raise ValueError("0 is not a valid value")
else:
return super().__new__(cls, x)

__add__ = check_for_0('__add__')
__sub__ = check_for_0('__sub__')

0 comments on commit 13ccce4

Please sign in to comment.