bpo-34333: Fix %-formatting in Path.with_suffix() (GH-8663)
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 11 Aug 2018 05:45:06 +0000 (08:45 +0300)
committerGitHub <noreply@github.com>
Sat, 11 Aug 2018 05:45:06 +0000 (08:45 +0300)
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2018-08-04-00-06-28.bpo-34333.5NHG93.rst [new file with mode: 0644]

index 4fe9d4aefc3b0cecbdaa23aa1cc22767a681515b..6be372ed320a2c4e1c2d98875260822304ba2623 100644 (file)
@@ -813,7 +813,7 @@ class PurePath(object):
         """
         f = self._flavour
         if f.sep in suffix or f.altsep and f.altsep in suffix:
-            raise ValueError("Invalid suffix %r" % (suffix))
+            raise ValueError("Invalid suffix %r" % (suffix,))
         if suffix and not suffix.startswith('.') or suffix == '.':
             raise ValueError("Invalid suffix %r" % (suffix))
         name = self.name
index d95a831b7b62d5f221d63608cf2fc7fa72fd6ac3..ae7c75deb0e6b7ed5f779199e854a696ea494a93 100644 (file)
@@ -577,6 +577,8 @@ class _BasePurePathTest(object):
         self.assertRaises(ValueError, P('a/b').with_suffix, '.c/.d')
         self.assertRaises(ValueError, P('a/b').with_suffix, './.d')
         self.assertRaises(ValueError, P('a/b').with_suffix, '.d/.')
+        self.assertRaises(ValueError, P('a/b').with_suffix,
+                          (self.flavour.sep, 'd'))
 
     def test_relative_to_common(self):
         P = self.cls
diff --git a/Misc/NEWS.d/next/Library/2018-08-04-00-06-28.bpo-34333.5NHG93.rst b/Misc/NEWS.d/next/Library/2018-08-04-00-06-28.bpo-34333.5NHG93.rst
new file mode 100644 (file)
index 0000000..000f684
--- /dev/null
@@ -0,0 +1,2 @@
+Fix %-formatting in :meth:`pathlib.PurePath.with_suffix` when formatting an
+error message.