From 65c0e11dc6ea486224558c4b43cbedfd9c5d81b5 Mon Sep 17 00:00:00 2001 From: gheshm-jpg Date: Wed, 9 Sep 2026 13:28:59 -0400 Subject: [PATCH] allow removing a file suffix with an empty string --- path/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/path/__init__.py b/path/__init__.py index 33dd979..b23b38b 100644 --- a/path/__init__.py +++ b/path/__init__.py @@ -339,12 +339,21 @@ def with_suffix(self, suffix: str) -> Self: >>> Path('python').with_suffix('.zip') Path('python.zip') + An empty suffix removes the final extension. + + >>> Path('some/archive.tar.gz').with_suffix('') + Path('some/archive.tar') + >>> Path('some/file').with_suffix('') + Path('some/file') + >>> Path('some/.config').with_suffix('') + Path('some/.config') + >>> Path('filename.ext').with_suffix('zip') Traceback (most recent call last): ... ValueError: Invalid suffix 'zip' """ - if not suffix.startswith('.'): + if suffix and not suffix.startswith('.'): raise ValueError(f"Invalid suffix {suffix!r}") return self.stripext() + suffix