Raymond Hettinger wrote:
FYI, I had already updated the patch to incorporate your suggestion.
It checks __index__ first and then __float__ if index doesn't exist.
The result makes it work with Decimal inputs.

Only sort of - the domain of the output is then constrained by what the builtin float type can represent, which strikes me as fairly inappropriate for what should be a lossless display operation (both fractions.Fraction and decimal.Decimal can represent a lot of numbers that float can't deal with properly). To use the old faithful example of this, given:

>>> float(Decimal("1.1"))
1.1000000000000001

what happens for bin(Decimal("1.1")) with the patch version that uses __float__?

As I've said elsewhere in this thread, I'm certainly not averse to the basic idea of letting bin/oct/hex handle rational numbers as well as integers, I just don't see it as something we have to have in the current release cycle, and nor do I see it really working properly without adding a __rational__ special method that returns a numerator/denominator 2-tuple (which would obviously require a PEP).

Cheers,
Nick.

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to