diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index c7d2b27d01adfc..e925d57ccbf081 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -927,7 +927,9 @@ def delete(self): """ Delete this file or directory (including all sub-directories). """ - if self.is_dir(follow_symlinks=False): + if self.is_symlink() or self.is_junction(): + self.unlink() + elif self.is_dir(): def on_error(err): raise err results = self.walk( diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index daadfb522c90b3..67b0cd125c4d4b 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -940,7 +940,10 @@ def test_delete_outer_junction(self): spam = src / 'spam' spam.write_text('') _winapi.CreateJunction(str(src), str(dst)) - self.assertRaises(OSError, dst.delete) + dst.delete() + self.assertFalse(dst.exists()) + self.assertTrue(spam.exists()) + self.assertTrue(src.exists()) @unittest.skipUnless(delete_use_fd_functions, "requires safe delete") def test_delete_fails_on_close(self):