[Python-ideas] Dunder method to make object str-like
Ethan Furman
ethan at stoneleaf.us
Thu Apr 7 11:00:44 EDT 2016
On 04/07/2016 06:46 AM, Émanuel Barry wrote:
> __index__ is meant to return the same thing as __int__, and I think the same
> restrictions should apply here
Do you mean "the same thing" as in both return 'int', or "the same
thing" is in __int__(3.4) == __index__(3.4) ? Because that last one is
False.
> - we have an object pretending to be a
> string, so there should *not* be a difference between use_as_string(obj) and
> use_as_string(str(obj))
Hmmm -- so maybe you are saying that if the results of __str__ and
__tostring__ are the same we're fine, just like if the results of
__int__ and __index__ are the same we're fine? Otherwise an error is
raised.
Sounds reasonable.
--
~Ethan~
More information about the Python-ideas
mailing list