Example #1
0
def eq_default(a, b):
    # This strongly enforces the null and boolean identity.
    # You can't mess it up by multimethod introductions.
    if a == null or b == null:
        return boolean(a == b)
    elif isinstance(a, Boolean) or isinstance(b, Boolean):
        return boolean(a == b)
    # This reflects how the cmp_ operates, with an exception that
    # if cmp cannot succeed, we will use the identity equality.
    args = [a, b]
    method = cmp_.fetch_method(args, True)
    if method is None:
        c = coerce.fetch_method(args, False)
        if c is not None:
            args = cast(c.call(args), List,
                        u"coerce should return a list").contents
            method = cmp_.fetch_method(args, True)
    if method is not None:
        return boolean(
            cast(method.call(args), Integer, u"cmp should return an int").value
            == 0)
    else:
        # This way, the equality and inequality is always defined,
        # even if comparison is not defined for everything.
        return boolean(a == b)
Example #2
0
def ge_default(a, b):
    args = [a, b]
    method = cmp_.fetch_method(args, True)
    if method is not None:
        return boolean(
            cast(method.call(args), Integer, u"cmp should return int").value >=
            0)
    else:
        args = cast(coerce.call(args), List, u"coerce should return a list")
        return ge.call_suppressed(args.contents)
Example #3
0
def cmp_default(a, b):
    args = cast(coerce.call([a, b]), List, u"coerce should return a list")
    return cmp_.call_suppressed(args.contents)