<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 7, 2016 at 11:59 AM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> class StringLike(abc.ABC):</div><div><br></div><div> @abstractmethod</div><div> def __str__(self):</div><div> """Return the string representation of something."""</div><div><br></div><div> StringLike.register(pathlib.PurePath) # Any 3rd-party library can do the same.</div><div><br></div><div>You could also call the class StringablePath or something and get the exact same concept across where you are using the registration abilities of ABCs to semantically delineate when a class's __str__() returns a usable file path.</div><div><br></div><div>The drawback is that this isn't easily backported like `path.__ospath__() if hasattr(path, '__ospath__') else path` for libraries that don't necessarily have access to pathlib but want to be compatible with accepting path objects.</div></div></div>
</blockquote></div><div class="gmail_extra"><br></div>and a plus is that it's compatible with type hinting -- is that the future of Python???<br><br><br>-CHB</div><div class="gmail_extra"><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>