New submission from Zbyszek Jędrzejewski-Szmek <zbys...@in.waw.pl>:
pathlib.Path.__truediv__(), i.e. pathlib.Path.joinpath() is surprising when the second argument starts with a slash. >>> pathlib.Path('/foo') / '/bar' >>> PosixPath('/bar') I know that this follows the precedent set by os.path.join(), and probably makes sense in some scenarios. But for the general operation of "concatenating paths", it doesn't fit very well. In particular, when concatenating multiple components this becomes even stranger: >>> pathlib.Path('/var/tmp/instroot') / '/some/path' / '/suffix' >>> PosixPath('/suffix') In my particular use case, I'm concatenating some user specified paths relative to some root. The paths may or may not be absolute. To avoid this pitfall, something like this is necessary: >>> pathlib.Path('/var/tmp/instroot') / p.lstrip('/') / q.lstrip('/') Please provide a way to do this natively. I think it'd be nice to use // or + for this: >>> pathlib.Path('/var/tmp/instroot') // '/some/path' // '/suffix' >>> PosixPath('/var/tmp/instroot/some/path/suffix') ---------- components: Library (Lib) messages: 396058 nosy: zbysz priority: normal severity: normal status: open title: Allow paths to be joined without worrying about a leading slash type: behavior versions: Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44452> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com