Proposal: === and !=== operators

Ian Kelly ian.g.kelly at
Wed Jul 9 20:31:28 CEST 2014

On Wed, Jul 9, 2014 at 12:05 PM, Tim Chase
<python.list at> 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