[Python-Dev] file system path protocol PEP (original) (raw)

Koos Zevenhoven k7hoven at gmail.com
Sun May 15 07:57:39 EDT 2016


On Fri, May 13, 2016 at 7:43 PM, Chris Angelico <rosuav at gmail.com> wrote: [...]

"Check" accepts subclasses; "CheckExact" doesn't (it's like "type(x) is str"). The question is, which one SHOULD be being done?

Indeed it should do "Check", so that path libraries that do inherit from str will still work (see also below).

What should this do:

class TmpPath(str): def fspath(self): return "/tmp/"+self x = TmpPath("foo/bar") open(x, "w") Does that respect fspath, or respect the fact that it's a string?

It should not respect fspath because that would mean the behavior is different in older versions of Python(!). This also means that such code should never be written (except for that example you wrote ;-). So indeed, composition would be the way to go.

So yes, I still think str subclasses should not implement fspath, and that, at the very least, the docs should say that :).

-- Koos

ChrisA


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/k7hoven%40gmail.com



More information about the Python-Dev mailing list