that is:
@abstractmethod
def __str__(self):
"""Return the string representation of the path, suitable for
passing to system calls."""
...
I don’t think this can stay. “Passing to system calls” only applicable to local filesystem paths. A JoinablePath does not, in general, have a representation you can pass to system calls.
You can “downcast” to a local filesystem path, and that could be implicit – “we trust the programmer to only call __str__ if it makes sense”. It would be good to be explicit about where the downcast happens, conceptually, between the JoinablePath and the syscall. Does __str__ do that (as the docstring above suggests), or do the os.unlink/open do it?
In my mental model, it happens when an os function interprets its argument. That is:
>>> os.unlink(PurePath('...')) # success... wait PurePath supports I/O?!
No, PurePath does not support I/O. You’re calling os.unlink, which interprets its input as a path on the real local filesystem.
If you do open(secrets.token_hex(), "w"), the token doesn’t support I/O either.
it’s perfectly legitimate to take the posixpath.basename() of a zip file member path
Yes, but taking the os.path.basename of it would be, conceptually, wrong.
The reason you can use posixpath.basename() is because you know an extra detail about zip files: they behave enough like Posix paths. You can’t use the function if you are working with truly generic JoinablePaths.
Sounds like zip paths can use __str__ as defined above. Then, zip paths would be special (relative to JoinablePath) in that their __str__ gives you a posix-path-shaped string.
Or maybe they should get a __posixpath__ method, to make this explicit for type-checkers (and brains trying to construct a mental model).
But I don’t think it would help to add a generic __vfspath__: that sounds like it would give you a string you can use with a specific “parser” module, but it would erase info about which module to use.
Or did you mean __vfspath__ to remain tied to the path’s parser module? The class itself would pass it to its parser, but the user shouldn’t call it (since they shouldn’t use the path’s parser directly, there’s nothing they can do with an internal string representation)?