GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-37609: Update ntpath.splitdrive to use native functionality where possible by zooba · Pull Request #25261 · python/cpython Conversation
|
| path = [p for p in (p1.rstrip(path_separators) for p1 in path) if p] | ||
| if not path: | ||
| # Avoid losing the root's trailing separator when joining with nothing | ||
| return root + path_sep | ||
| return root + path_sep.join(path) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_path_join('//server/share', 'spam') should return "//server/share/spam", not "//server/sharespam"_path_join("C:/", "spam") should return "C:/spam", not "C:spam"_path_join("C:", "") should return "C:", not "C:\"._path_join("C:", "D:") should return "D:", not "D:\"I don't like the change to make _path_splitroot() shift the separator into the path. It goes against what I expect given the function name, in terms of separating the root from the rest of the path. The root variable here actually has no root path, which is counterintuitive.
As it stands, the following fixes the above case by shifting the separator back into root. The UNC + relative case has to be handled specially at the end.
if path and path[0].startswith(path_sep_tuple): root += path[0][0] path[0] = path[0][1:] tail = path_sep.join(c for p in path if (c := p.rstrip(path_separators))) # Fix up appending a relative path to a UNC root if (tail and root.startswith(path_sep_tuple) and not root.endswith(path_sep_tuple) and not tail.startswith(path_sep_tuple)): root += path_sep return root + tail
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| else: | ||
| def _splitroot(p): | ||
| p = os.fspath(p) | ||
| r = _path_splitroot(p) | ||
| if isinstance(p, bytes): | ||
| return tuple(map(os.fsencode, r)) | ||
| return r |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the name to nt._path_splitdrive, since that makes more sense now that the root is shifted over to the path side. Implement the POSIX fallback as _path_splitdrive, which only returns str, just like the builtin function. Move the above bytes support code into a common implementation of ntpath.splitdrive(), which is likely the only place it will ever be needed. _path_splitdrive() will be used directly when bytes support isn't required.
I'm sure you know the os.fspath() call isn't necessary since it's handled for a path_t argument in C, so why is it called explicitly here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The isinstance at 69 needs to recognise values for p that have __fspath__ that returns bytes, as well as actual bytes, which is why we fspath once instead of doing it multiple times.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The
isinstanceat 69 needs to recognise values forpthat have__fspath__that returns bytes, as well as actual bytes, which is why wefspathonce instead of doing it multiple times.
Sigh... sorry about that. :-$
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Frankly, I'm out of energy for this patch. Someone else can work on it if they're keen, or maybe I'll get back to it one day. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thank you for all of your work here. Do you want to repurpose the work for test_ntpath.py in a new issue, to refine exactly what should be be supported by |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.