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

Random832 random832 at fastmail.com
Mon Apr 11 10:57:47 EDT 2016

On Mon, Apr 11, 2016, at 10:43, Nikolaus Rath wrote:
> To me this sounds like catering to a hypothetical audience that may want
> to do hypothetical things. If you start with the above, and people
> complain that their favorite non-pathlib path library is not supported
> by the stdlib, you can still add a protocol. But if you add a protocol
> right away, you're stuck with the complexity for a very long time even
> if almost no one actually uses it.

And there's nothing stopping people from subclassing from Path (should
it be PurePath?), or monkey-patching pathlib. In this case,
"isinstance(foo, Path) returns true" is the protocol.

Also, where is the .path attribute? It's documented

>>> pathlib.Path(".").path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'PosixPath' object has no attribute 'path'

More information about the Python-ideas mailing list