<commit_before># -*- coding: utf-8 -*-


"""
Provides the AccountingNone singleton

AccountingNone is a null value that dissolves in basic arithmetic operations,
as illustrated in the examples below

>>> 1 + 1
2
>>> 1 + AccountingNone
1
>>> AccountingNone + 1
1
>>> AccountingNone + None
AccountingNone
>>> +AccountingNone
AccountingNone
>>> -AccountingNone
AccountingNone
>>> -(AccountingNone)
AccountingNone
>>> AccountingNone - 1
-1
>>> 1 - AccountingNone
1
>>> AccountingNone - None
AccountingNone
>>> AccountingNone / 2
0.0
>>> 2 / AccountingNone
Traceback (most recent call last):
 ...
ZeroDivisionError
>>> AccountingNone / AccountingNone
AccountingNone
>>> AccountingNone // 2
0.0
>>> 2 // AccountingNone
Traceback (most recent call last):
 ...
ZeroDivisionError
>>> AccountingNone // AccountingNone
AccountingNone
>>> AccountingNone * 2
0.0
>>> 2 * AccountingNone
0.0
>>> AccountingNone * AccountingNone
AccountingNone
>>> AccountingNone * None
AccountingNone
"""


class AccountingNoneType(object):

    def __add__(self, other):
        if other is None:
            return AccountingNone
        return other

    __radd__ = __add__

    def __sub__(self, other):
        if other is None:
            return AccountingNone
        return -other

    def __rsub__(self, other):
        if other is None:
            return AccountingNone
        return other

    def __iadd__(self, other):
        if other is None:
            return AccountingNone
        return other

    def __isub__(self, other):
        if other is None:
            return AccountingNone
        return -other

    def __pos__(self):
        return self

    def __neg__(self):
        return self

    def __floordiv__(self, other):
        """
        Overload of the // operator
        """
        if other is AccountingNone:
            return AccountingNone
        return 0.0

    def __rfloordiv__(self, other):
        raise ZeroDivisionError

    def __truediv__(self, other):
        """
        Overload of the / operator
        """
        if other is AccountingNone:
            return AccountingNone
        return 0.0

    def __rtruediv__(self, other):
        raise ZeroDivisionError

    def __mul__(self, other):
        if other is None or other is AccountingNone:
            return AccountingNone
        return 0.0

    def __rmul__(self, other):
        if other is None or other is AccountingNone:
            return AccountingNone
        return 0.0

    def __repr__(self):
        return 'AccountingNone'

    def __unicode__(self):
        return ''


AccountingNone = AccountingNoneType()


if __name__ == '__main__':
    import doctest
    doctest.testmod()<commit_msg>[IMP] improve AccountingNone wrt comparisons mainly<commit_after># -*- coding: utf-8 -*-


"""
Provides the AccountingNone singleton

AccountingNone is a null value that dissolves in basic arithmetic operations,
as illustrated in the examples below. In comparisons, AccountingNone behaves
the same as zero.

>>> 1 + 1
2
>>> 1 + AccountingNone
1
>>> AccountingNone + 1
1
>>> AccountingNone + None
AccountingNone
>>> +AccountingNone
AccountingNone
>>> -AccountingNone
AccountingNone
>>> -(AccountingNone)
AccountingNone
>>> AccountingNone - 1
-1
>>> 1 - AccountingNone
1
>>> AccountingNone - None
AccountingNone
>>> AccountingNone / 2
0.0
>>> 2 / AccountingNone
Traceback (most recent call last):
 ...
ZeroDivisionError
>>> AccountingNone / AccountingNone
AccountingNone
>>> AccountingNone // 2
0.0
>>> 2 // AccountingNone
Traceback (most recent call last):
 ...
ZeroDivisionError
>>> AccountingNone // AccountingNone
AccountingNone
>>> AccountingNone * 2
0.0
>>> 2 * AccountingNone
0.0
>>> AccountingNone * AccountingNone
AccountingNone
>>> AccountingNone * None
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
"""


class AccountingNoneType(object):

    def __add__(self, other):
        if other is None:
            return AccountingNone
        return other

    __radd__ = __add__

    def __sub__(self, other):
        if other is None:
            return AccountingNone
        return -other

    def __rsub__(self, other):
        if other is None:
            return AccountingNone
        return other

    def __iadd__(self, other):
        if other is None:
            return AccountingNone
        return other

    def __isub__(self, other):
        if other is None:
            return AccountingNone
        return -other

    def __pos__(self):
        return self

    def __neg__(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):
        if other is AccountingNone:
            return AccountingNone
        return 0.0

    def __rfloordiv__(self, other):
        raise ZeroDivisionError

    def __truediv__(self, other):
        if other is AccountingNone:
            return AccountingNone
        return 0.0

    def __rtruediv__(self, other):
        raise ZeroDivisionError

    def __mul__(self, other):
        if other is None or other is AccountingNone:
            return AccountingNone
        return 0.0

    __rmul__ = __mul__

    def __repr__(self):
        return 'AccountingNone'

    def __str__(self):
        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()


if __name__ == '__main__':
    import doctest
    doctest.testmod()
{'fraction_non_alphanumeric': 0.08668076109936575, 'fraction_numerical': 0.01333550170759473, 'mean_word_length': 2.600702576112412, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 170, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4136390', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1726, 'n_words': 566}