pathlib.Path.parts - tuple of path objects rather than strings?
One occasional problem I have with pathlib.Path.parts is that it returns a tuple of strings. For WindowsPath objects, paths are case insensitive but strings aren't. So we get the situation that
p1 = pathlib.PureWindowsPath('foo') p2 = pathlib.PureWindowsPath('FOO') p1 == p2 True p1.parts == p2.parts False
Making p1.parts return a tuple of objects of type p1.__class__ would address this:
[p1.__class__(p) for p in p1.parts] == [p2.__class__(p) for p in p2.parts] True
Is this something that's worth changing (pathlib is still provisional, so the backward compatibility break would technically be allowed, even if it's not ideal)? Or would an extra property, say p.path_parts that returned a tuple of path objects be worth considering? As it is, use of path.parts is a potential source of portability bugs, where Unix users don't consider the case sensitivity issue. (Heck, as a Windows user, I almost missed the problem in my implementation of common_prefix, so it's not just Unix users...) Paul
participants (1)
-
Paul Moore