[Python-ideas] math.inf and math.nan constants

Chris Angelico rosuav at gmail.com
Mon Jan 12 02:05:11 CET 2015


On Mon, Jan 12, 2015 at 10:55 AM, Chris Barker <chris.barker at noaa.gov> wrote:
> Though it would be pretty cool if you could override "is" to make:
>
> x is math.nan
>
> be:
>
> math.isnan(x)

No, it wouldn't! It'd be cute, it'd read really nicely the first time,
but breaking the definition of object identity is a Bad Thing. For
instance, imagine this:

x = 0*1e400
y = 1e400-1e400
z = math.nan
print(x is y, y is z, x is z)

If you hide the first three lines and look only at the last one, you
would expect that "False True True" is an impossible result. But
that's exactly what redefining "is" could do.

ChrisA


More information about the Python-ideas mailing list