[Python-ideas] Dunder method to make object str-like
rosuav at gmail.com
Thu Apr 7 14:53:34 EDT 2016
On Fri, Apr 8, 2016 at 4:42 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> On 07.04.2016 18:46, Chris Angelico wrote:
>> On Fri, Apr 8, 2016 at 2:27 AM, M.-A. Lemburg <mal at egenix.com> wrote:
>>> Not necessarily. In fact, a string.String ABC could have only
>>> a single method: .__str__() defined.
>> That wouldn't be very useful; object.__str__ exists and is functional,
>> so EVERY object would count as a string.
> No, only those objects that register with the ABC would be considered
> string-like, not all objects implementing the .__str__() method.
> In regular Python, only str() objects would register with
In that case, it would still be pretty much the same as the __fspath__
proposal, except that instead of creating a dunder method (to
implement a protocol), you register with an ABC.
More information about the Python-ideas