[Python-Dev] PEP for adding an sq_index slot so that any object, a or b, can be used in X[a:b] notation
Adam Olsen
rhamph at gmail.com
Thu Feb 9 22:14:43 CET 2006
On 2/9/06, Travis E. Oliphant <oliphant.travis at ieee.org> wrote:
> I'm a little confused. Is your opposition solely due to the fact that
> you think float's __int__ method ought to raise exceptions and the
> apply_slice code should therefore use the __int__ slot?
>
> In theory I can understand this reasoning. In practice, however, the
> __int__ slot has been used for "coercion" and changing the semantics of
> int(3.2) at this stage seems like a recipe for lots of code breakage. I
> don't think something like that is possible until Python 3k.
>
> If that is not your opposition, please be more clear. Regardless of how
> it is done, it seems rather unPythonic to only allow 2 special types to
> be used in apply_slice and assign_slice.
Yes, that is the basis of my opposition, and I do understand it would
take a long time to change __int__.
What is the recommended practice for python? I can think of three
distinct categories of behavior:
- float to str. Some types converted to str might by lossy, but in
general it's a very drastic conversion and unrelated to the others
- float to Decimal. Raises an exception because it's usually lossy.
- Decimal to int. Truncates, quite happily losing precision..
I guess my confusion revolves around float to Decimal. Is lossless
conversion a good thing in python, or is prohibiting float to Decimal
conversion just a fudge to prevent people from initializing a Decimal
from a float when they really want a str?
--
Adam Olsen, aka Rhamphoryncus
More information about the Python-Dev
mailing list