Proposal: === and !=== operators

Ian Kelly ian.g.kelly at gmail.com
Wed Jul 9 14:31:28 EDT 2014


On Wed, Jul 9, 2014 at 12:05 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
>  def equalish(x, y):
>    return x == y or (math.isnan(x) and math.isnan(y))

With more generality:

def nan_type(x):
    if isinstance(x, numbers.Complex):
        if cmath.isnan(x): return 'qnan'
    elif isinstance(x, decimal.Decimal):
        if x.is_qnan(): return 'qnan'
        if x.is_snan(): return 'snan'
    return None

def equalish(x, y):
    if x is y or x == y: return True
    x_nan = nan_type(x)
    return x_nan is not None and x_nan == nan_type(y)

Have I missed any cases?



More information about the Python-list mailing list