diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 4fe9d4aefc3..6be372ed320 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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 diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index d95a831b7b6..ae7c75deb0e 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -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 index 00000000000..000f6842255 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-08-04-00-06-28.bpo-34333.5NHG93.rst @@ -0,0 +1,2 @@ +Fix %-formatting in :meth:`pathlib.PurePath.with_suffix` when formatting an +error message.