[Python-ideas] Dunder method to make object str-like

Chris Angelico rosuav at gmail.com
Fri Apr 8 02:03:42 EDT 2016

On Fri, Apr 8, 2016 at 3:51 PM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> Anything
> where you combine it with bytes has to result in bytes, or prepare for
> the combining operation to raise if the bytes contain any non-ASCII.

More helpfully, the Ascii object would raise *before* that - it would
raise on construction if it had any non-ASCII in it. Combining an
Ascii with a bytes results in a perfectly well-formed bytes; combining
an Ascii with a unicode results in a perfectly well-formed unicode.

But I'm not sure how (a) useful and (b) feasible this is. The only
real use-case I know of is Path objects, and there may be similar
tasks around numpy or pandas, but I don't know for sure.


More information about the Python-ideas mailing list