A rational proposal

Nick Coghlan ncoghlan at iinet.net.au
Thu Dec 23 02:17:04 EST 2004
Mike Meyer wrote:
> Actually, I suggested that:
> 
> float() + Rational() returns float
> 
> You're suggesting that the implicit conversion to float not happen
> here, and the user be forced to cast it to float? And you're saying
> Decimal does it that way.[

Yup.

I had another look at PEP 327 (the section on implicit construction) and the 
reasoning that got us to that behaviour wasn't quite what I thought. However, I 
think the point still holds for Rational - the conversion often won't be exact 
in either direction, so it's OK for Python to ask the programmer to confirm that 
they really want to make the conversion.

I think adding subsections modelled on PEP 327's "Explicit construction", 
"Implicit construction" and "Python usability" would be a big plus for the new 
Rational PEP. The layout Facundo used makes it obvious that issues of playing 
well with other types have been considered properly.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list