[issue4087] Document the effects of NotImplemented on == and !=
Terry J. Reedy
report at bugs.python.org
Fri Oct 10 21:57:34 CEST 2008
Terry J. Reedy <tjreedy at udel.edu> added the comment:
More sensibility offenders:
>>> s = {fractions.Fraction(17,1), decimal.Decimal(17)}
>>> s-{17}
set()
Removing one thing removes two.
>>> s.remove(17)
>>> 17 in s
True
Removing something leaves it there.
>>> s
{Fraction(17, 1)} # random choice
Removing one thing and subtracting the set with that one thing give
different results.
>>> s = {decimal.Decimal(17), fractions.Fraction(17,1)}
>>> s.remove(17)
>>> s
{Decimal('17')}
The behavior of 'set' s depends on the order items are added.
> Facundo's suggested code:
if isinstance(other, float) and int(other)==other:
other = int(other)
would be more efficient, I assume as
if isinstance(other,float):
ifloat = int(other)
if other == ifloat:
other = ifloat
or if the CAPI has an efficient 'float_isint' function that accesses the
bits of a float, as the C equivalent of
if isinstance(other, float) and float_isint(other):
other = int(other)
I remember float-Decimal comparison being rejected/deferred in part for
being problematical for fractional values. That is why I suggested
implementing it, at least for the present, for integral floats (and
Fractions) only, which are relatively easy to detect.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4087>
_______________________________________
More information about the Python-bugs-list
mailing list