(T, S)
Coerce types T and S to a common type, or raise TypeError.

    Coercion rules are currently an implementation detail. See the CoerceTest
    test class in test_statistics for details.
Coerce types T and S to a common type, or raise TypeError.
Coerce types T and S to a common type or raise TypeError .
def _coerce(T, S):
    """Coerce types T and S to a common type, or raise TypeError.

    Coercion rules are currently an implementation detail. See the CoerceTest
    test class in test_statistics for details.
    """
    # See http://bugs.python.org/issue24068.
    assert T is not bool, "initial type T is bool"
    # If the types are the same, no need to coerce anything. Put this
    # first, so that the usual case (no coercion needed) happens as soon
    # as possible.
    if T is S:  return T
    # Mixed int & other coerce to the other type.
    if S is int or S is bool:  return T
    if T is int:  return S
    # If one is a (strict) subclass of the other, coerce to the subclass.
    if issubclass(S, T):  return S
    if issubclass(T, S):  return T
    # Ints coerce to the other type.
    if issubclass(T, int):  return S
    if issubclass(S, int):  return T
    # Mixed fraction & float coerces to float (or float subclass).
    if issubclass(T, Fraction) and issubclass(S, float):
        return S
    if issubclass(T, float) and issubclass(S, Fraction):
        return T
    # Any other combination is disallowed.
    msg = "don't know how to coerce %s and %s"
    raise TypeError(msg % (T.__name__, S.__name__))
def _coerce ( T , S ) : # See http://bugs.python.org/issue24068. assert T is not bool , "initial type T is bool" # If the types are the same, no need to coerce anything. Put this # first, so that the usual case (no coercion needed) happens as soon # as possible. if T is S : return T # Mixed int & other coerce to the other type. if S is int or S is bool : return T if T is int : return S # If one is a (strict) subclass of the other, coerce to the subclass. if issubclass ( S , T ) : return S if issubclass ( T , S ) : return T # Ints coerce to the other type. if issubclass ( T , int ) : return S if issubclass ( S , int ) : return T # Mixed fraction & float coerces to float (or float subclass). if issubclass ( T , Fraction ) and issubclass ( S , float ) : return S if issubclass ( T , float ) and issubclass ( S , Fraction ) : return T # Any other combination is disallowed. msg = "don't know how to coerce %s and %s" raise TypeError ( msg % ( T . __name__ , S . __name__ ) )