8000 gh-101000: Add os.path.splitroot() by barneygale · Pull Request #101002 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101000: Add os.path.splitroot() #101002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jan 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
21c0ba9
gh-101000: Add os.path.splitroot()
barneygale Jan 12, 2023
836b85d
Use splitroot() from pathlib
barneygale Jan 12, 2023
bc2d1f9
Use splitroot() from posixpath
barneygale Jan 12, 2023
ecdc40d
Use splitroot() from ntpath
barneygale Jan 12, 2023
6592b27
Optimizations
barneygale Jan 12, 2023
78f4227
Correct and expand examples in splitroot() docstring
barneygale Jan 13, 2023
9726ca4
Update Lib/ntpath.py
barneygale Jan 13, 2023
7a6613c
Use splitroot() from pathlib.PurePath.with_name()
barneygale Jan 14, 2023
26a8dba
Reduce ntpath.normpath() diff noise
barneygale Jan 15, 2023
0c237d4
Simplify ntpath.commonpath() now that 'isabs' is unused.
barneygale Jan 15, 2023
11ed3eb
Reduce posixpath.normpath() diff noise
barneygale Jan 15, 2023
2c9eed8
Improve documentation
barneygale Jan 15, 2023
8299e96
Add whatsnew entry.
barneygale Jan 15, 2023
27ffe37
Simplify ntpath.splitroot() slightly
barneygale Jan 15, 2023
9beff2a
Apply suggestions from code review
barneygale Jan 16, 2023
bacdee1
Update Doc/library/os.path.rst
barneygale Jan 16, 2023
4ebe545
Note that drive may be empty on Windows
barneygale Jan 16, 2023
2927afe
Re-order drive example
barneygale Jan 16, 2023
b0aa73e
Update Doc/library/os.path.rst
barneygale Jan 16, 2023
19777d6
Adjust docstring examples
barneygale Jan 18, 2023
32e212e
Apply suggestions from code review
barneygale Jan 19, 2023
37cded3
Update Doc/library/os.path.rst
barneygale Jan 19, 2023
5a8dfce
Change example username in docs to 'Sam'
barneygale Jan 19, 2023
0e75a55
Adjust first paragraph to use prose
barneygale Jan 19, 2023
3663237
Update Doc/library/os.path.rst
barneygale Jan 22, 2023
053729d
Add tests for bytes (POSIX only) and path-like objects (both platforms)
barneygale Jan 22, 2023
694f093
Add tests for mixed path separators (Windows only)
barneygale Jan 22, 2023
e99e3cd
Remove errant newline.
barneygale Jan 22, 2023
f618a00
Move most test cases from `test_splitdrive` to `test_splitroot`
barneygale Jan 22, 2023
1c522c9
Mention pathlib performance improvement in news entry.
barneygale Jan 22, 2023
df17269
Merge branch 'main' into gh-101000-splitroot
AlexWaygood Jan 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Prev Previous commit
Next Next commit
Simplify ntpath.splitroot() slightly
  • Loading branch information
barneygale committed Jan 15, 2023
commit 27ffe37a991ab0a2c8e25b5bfc72630026f2c37c
14 changes: 6 additions & 8 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,13 @@ def splitroot(p):
if p[:1] != sep:
# Relative path, e.g.: 'foo'
return empty, empty, p
elif p[1:2] != sep:
# Absolute path, e.g.: '/foo'
return empty, p[:1], p[1:]
elif p[2:3] != sep:
# Implementation defined per POSIX standard, e.g.: '//foo'
return empty, p[:2], p[2:]
elif p[1:2] != sep or p[2:3] == sep:
# Absolute path, e.g.: '/foo', '///foo', '////foo', etc.
return empty, sep, p[1:]
else:
# Absolute path with extraneous slashes, e.g.: '///foo', '////foo', etc.
return empty, p[:1], p[1:]
# Precisely two leading slashes, e.g.: '//foo'. Implementation defined per POSIX, see
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
return empty, p[:2], p[2:]


# Return the tail (basename) part of a path, same as split(path)[1].
Expand Down
0