[Python-ideas] Dunder method to make object str-like
p.f.moore at gmail.com
Thu Apr 7 13:16:56 EDT 2016
On 7 April 2016 at 17:16, Random832 <random832 at fastmail.com> wrote:
> On Thu, Apr 7, 2016, at 11:01, Paul Moore wrote:
>> >> For that matter, what constitutes a "lossless conversion to str"?
>> > What's __index__ for?
>> I don't follow. It's for indexing, which requires an integer.
> Sure, but why isn't int() good enough? For the same reason you only want
> the kinds of objects that implement __index__ (and not, say, a float or
> a string that happens to be numeric) for indexing, you only want the
> kinds of objects that implement this method for certain purposes.
You're making my point here. A "lossless conversion to str" isn't a
good enough definition of which things should implement the new
protocol. I'm trying to get someone to tell me what criteria I should
use to decide if my type should implement the new protocol. At the
moment, I have no idea.
More information about the Python-ideas