]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-82805: Fix handling of single-dot file extensions in pathlib (#118952)
authorBarney Gale <barney.gale@gmail.com>
Sat, 25 May 2024 20:01:36 +0000 (21:01 +0100)
committerGitHub <noreply@github.com>
Sat, 25 May 2024 20:01:36 +0000 (21:01 +0100)
commite418fc3a6e7bade68ab5dfe72f14ddba28e6acb5
tree67662f1eba24dd69bfef714d0a48e1274927b480
parent0c5ebe13e9937c446e9947c44f2570737ecca135
GH-82805: Fix handling of single-dot file extensions in pathlib (#118952)

pathlib now treats "`.`" as a valid file extension (suffix). This brings
it in line with `os.path.splitext()`.

In the (private) pathlib ABCs, we add a new `ParserBase.splitext()` method
that splits a path into a `(root, ext)` pair, like `os.path.splitext()`.
This method is called by `PurePathBase.stem`, `suffix`, etc. In a future
version of pathlib, we might make these base classes public, and so users
will be able to define their own `splitext()` method to control file
extension splitting.

In `pathlib.PurePath` we add optimised `stem`, `suffix` and `suffixes`
properties that don't use `splitext()`, which avoids computing the path
base name twice.
Doc/library/pathlib.rst
Lib/pathlib/_abc.py
Lib/pathlib/_local.py
Lib/test/test_pathlib/test_pathlib_abc.py
Misc/NEWS.d/next/Library/2024-05-11-20-23-45.gh-issue-82805.F9bz4J.rst [new file with mode: 0644]