<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, 7 Apr 2016 at 12:11 Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 04/07/2016 11:59 AM, Brett Cannon wrote:<br>
<br>
> To make MAL's proposal concrete:<br>
><br>
>    class StringLike(abc.ABC):<br>
><br>
>      @abstractmethod<br>
>      def __str__(self):<br>
>          """Return the string representation of something."""<br>
><br>
>    StringLike.register(pathlib.PurePath)  # Any 3rd-party library can do<br>
> the same.<br>
><br>
> You could also call the class StringablePath or something and get the<br>
> exact same concept across where you are using the registration abilities<br>
> of ABCs to semantically delineate when a class's __str__() returns a<br>
> usable file path.<br>
<br>
I think I might like this better than a new magic method.<br>
<br>
> The drawback is that this isn't easily backported like<br>
> `path.__ospath__() if hasattr(path, '__ospath__') else path` for<br>
> libraries that don't necessarily have access to pathlib but want to be<br>
> compatible with accepting path objects.<br>
<br>
I don't understand.<br></blockquote><div><br></div><div>How do you make Python 3.3 code work with this when the ABC will simply not be available to you unless you're running Python 3.4.3, 3.5.2, or 3.6.0 (under the assumption that the ABC is put in pathlib and backported thanks to its provisional status)? The ternary operator one-liner is backwards-compatible while the ABC is only forward-compatible. </div></div></div>