GH-128520: pathlib ABCs: validate magic_open() arguments (#131617)

When `pathlib._os.magic_open()` is called to open a path in binary mode,
raise `ValueError` if any of the *encoding*, *errors* or *newline*
arguments are given. This matches the `open()` built-in.
This commit is contained in:
Barney Gale 2025-03-24 15:13:18 +00:00 committed by GitHub
parent fbfb0e1f6e
commit d716ea34cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -39,6 +39,9 @@ class ReadTestBase:
p = self.root / 'fileA'
with magic_open(p, 'rb') as f:
self.assertEqual(f.read(), b'this is file A\n')
self.assertRaises(ValueError, magic_open, p, 'rb', encoding='utf8')
self.assertRaises(ValueError, magic_open, p, 'rb', errors='strict')
self.assertRaises(ValueError, magic_open, p, 'rb', newline='')
def test_read_bytes(self):
p = self.root / 'fileA'