Skip to content

Commit c614121

Browse files
bpo-34333: Fix %-formatting in Path.with_suffix() (GH-8663)
(cherry picked from commit 423d05f) Co-authored-by: Berker Peksag <berker.peksag@gmail.com>
1 parent ea8835f commit c614121

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Lib/pathlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def with_suffix(self, suffix):
813813
"""
814814
f = self._flavour
815815
if f.sep in suffix or f.altsep and f.altsep in suffix:
816-
raise ValueError("Invalid suffix %r" % (suffix))
816+
raise ValueError("Invalid suffix %r" % (suffix,))
817817
if suffix and not suffix.startswith('.') or suffix == '.':
818818
raise ValueError("Invalid suffix %r" % (suffix))
819819
name = self.name

Lib/test/test_pathlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ def test_with_suffix_common(self):
577577
self.assertRaises(ValueError, P('a/b').with_suffix, '.c/.d')
578578
self.assertRaises(ValueError, P('a/b').with_suffix, './.d')
579579
self.assertRaises(ValueError, P('a/b').with_suffix, '.d/.')
580+
self.assertRaises(ValueError, P('a/b').with_suffix,
581+
(self.flavour.sep, 'd'))
580582

581583
def test_relative_to_common(self):
582584
P = self.cls
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix %-formatting in :meth:`pathlib.PurePath.with_suffix` when formatting an
2+
error message.

0 commit comments

Comments
 (0)