|
@ -5,7 +5,8 @@ |
|
|
Provides the AccountingNone singleton |
|
|
Provides the AccountingNone singleton |
|
|
|
|
|
|
|
|
AccountingNone is a null value that dissolves in basic arithmetic operations, |
|
|
AccountingNone is a null value that dissolves in basic arithmetic operations, |
|
|
as illustrated in the examples below |
|
|
|
|
|
|
|
|
as illustrated in the examples below. In comparisons, AccountingNone behaves |
|
|
|
|
|
the same as zero. |
|
|
|
|
|
|
|
|
>>> 1 + 1 |
|
|
>>> 1 + 1 |
|
|
2 |
|
|
2 |
|
@ -51,6 +52,34 @@ AccountingNone |
|
|
AccountingNone |
|
|
AccountingNone |
|
|
>>> AccountingNone * None |
|
|
>>> AccountingNone * None |
|
|
AccountingNone |
|
|
AccountingNone |
|
|
|
|
|
>>> None * AccountingNone |
|
|
|
|
|
AccountingNone |
|
|
|
|
|
>>> str(AccountingNone) |
|
|
|
|
|
'' |
|
|
|
|
|
>>> bool(AccountingNone) |
|
|
|
|
|
False |
|
|
|
|
|
>>> AccountingNone > 0 |
|
|
|
|
|
False |
|
|
|
|
|
>>> AccountingNone < 0 |
|
|
|
|
|
False |
|
|
|
|
|
>>> AccountingNone < 1 |
|
|
|
|
|
True |
|
|
|
|
|
>>> AccountingNone > 1 |
|
|
|
|
|
False |
|
|
|
|
|
>>> 0 < AccountingNone |
|
|
|
|
|
False |
|
|
|
|
|
>>> 0 > AccountingNone |
|
|
|
|
|
False |
|
|
|
|
|
>>> 1 < AccountingNone |
|
|
|
|
|
False |
|
|
|
|
|
>>> 1 > AccountingNone |
|
|
|
|
|
True |
|
|
|
|
|
>>> AccountingNone == 0 |
|
|
|
|
|
True |
|
|
|
|
|
>>> AccountingNone == 0.0 |
|
|
|
|
|
True |
|
|
|
|
|
>>> AccountingNone == None |
|
|
|
|
|
True |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,10 +118,15 @@ class AccountingNoneType(object): |
|
|
def __neg__(self): |
|
|
def __neg__(self): |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
def __div__(self, other): |
|
|
|
|
|
if other is AccountingNone: |
|
|
|
|
|
return AccountingNone |
|
|
|
|
|
return 0.0 |
|
|
|
|
|
|
|
|
|
|
|
def __rdiv__(self, other): |
|
|
|
|
|
raise ZeroDivisionError |
|
|
|
|
|
|
|
|
def __floordiv__(self, other): |
|
|
def __floordiv__(self, other): |
|
|
""" |
|
|
|
|
|
Overload of the // operator |
|
|
|
|
|
""" |
|
|
|
|
|
if other is AccountingNone: |
|
|
if other is AccountingNone: |
|
|
return AccountingNone |
|
|
return AccountingNone |
|
|
return 0.0 |
|
|
return 0.0 |
|
@ -101,9 +135,6 @@ class AccountingNoneType(object): |
|
|
raise ZeroDivisionError |
|
|
raise ZeroDivisionError |
|
|
|
|
|
|
|
|
def __truediv__(self, other): |
|
|
def __truediv__(self, other): |
|
|
""" |
|
|
|
|
|
Overload of the / operator |
|
|
|
|
|
""" |
|
|
|
|
|
if other is AccountingNone: |
|
|
if other is AccountingNone: |
|
|
return AccountingNone |
|
|
return AccountingNone |
|
|
return 0.0 |
|
|
return 0.0 |
|
@ -116,17 +147,29 @@ class AccountingNoneType(object): |
|
|
return AccountingNone |
|
|
return AccountingNone |
|
|
return 0.0 |
|
|
return 0.0 |
|
|
|
|
|
|
|
|
def __rmul__(self, other): |
|
|
|
|
|
if other is None or other is AccountingNone: |
|
|
|
|
|
return AccountingNone |
|
|
|
|
|
return 0.0 |
|
|
|
|
|
|
|
|
__rmul__ = __mul__ |
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
def __repr__(self): |
|
|
return 'AccountingNone' |
|
|
return 'AccountingNone' |
|
|
|
|
|
|
|
|
def __unicode__(self): |
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
return '' |
|
|
return '' |
|
|
|
|
|
|
|
|
|
|
|
def __nonzero__(self): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __bool__(self): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other): |
|
|
|
|
|
return other == 0 or other is None or other is AccountingNone |
|
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other): |
|
|
|
|
|
return 0 < other |
|
|
|
|
|
|
|
|
|
|
|
def __gt__(self, other): |
|
|
|
|
|
return 0 > other |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AccountingNone = AccountingNoneType() |
|
|
AccountingNone = AccountingNoneType() |
|
|
|
|
|
|
|
|