8000 GH-82805: Fix handling of single-dot file extensions in pathlib by barneygale · Pull Request #118952 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-82805: Fix handling of single-dot file extensions in pathlib #118952

8000
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 4 commits into from
May 25, 2024

Conversation

barneygale
Copy link
Contributor
@barneygale barneygale commented May 11, 2024

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.


📚 Documentation preview 📚: https://cpython-previews--118952.org.readthedocs.build/

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.
@barneygale barneygale merged commit e418fc3 into python:main May 25, 2024
33 checks passed
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…python#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0