GH-114610: Fix pathlib.PurePath.with_stem('') handling of file extensions (#114612)

Raise `ValueError` if `with_stem('')` is called on a path with a file
extension. Paths may only have an empty stem if they also have an empty
suffix.
This commit is contained in:
Barney Gale 2024-02-24 19:37:03 +00:00 committed by GitHub
parent 53c5c17e0a
commit e3dedeae7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View file

@ -957,6 +957,8 @@ class DummyPurePathTest(unittest.TestCase):
self.assertEqual(P('/').with_stem('d'), P('/d'))
self.assertEqual(P('a/b').with_stem(''), P('a/'))
self.assertEqual(P('a/b').with_stem('.'), P('a/.'))
self.assertRaises(ValueError, P('foo.gz').with_stem, '')
self.assertRaises(ValueError, P('/a/b/foo.gz').with_stem, '')
def test_with_stem_seps(self):
P = self.cls