8000 [3.13] gh-71253: Match _io exception in _pyio (gh-133985) (gh-134431) · python/cpython@046125e · GitHub
[go: up one dir, main page]

Skip to content

Commit 046125e

Browse files
miss-islingtoncmaloneyZeroIntensity
authored
[3.13] gh-71253: Match _io exception in _pyio (gh-133985) (gh-134431)
Test was only testing _io, expanded to cover _pyio. (cherry picked from commit 06eaf40) Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent de6d199 commit 046125e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Lib/_pyio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,8 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
15591559
if not isinstance(fd, int):
15601560
raise TypeError('expected integer from opener')
15611561
if fd < 0:
1562-
raise OSError('Negative file descriptor')
1562+
# bpo-27066: Raise a ValueError for bad value.
1563+
raise ValueError(f'opener returned {fd}')
15631564
owned_fd = fd
15641565
if not noinherit_flag:
< 8000 div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">
15651566
os.set_inheritable(fd, False)

Lib/test/test_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,15 +894,15 @@ def test_bad_opener_negative_1(self):
894894
def badopener(fname, flags):
895895
return -1
896896
with self.assertRaises(ValueError) as cm:
897-
open('non-existent', 'r', opener=badopener)
897+
self.open('non-existent', 'r', opener=badopener)
898898
self.assertEqual(str(cm.exception), 'opener returned -1')
899899

900900
def test_bad_opener_other_negative(self):
901901
# Issue #27066.
902902
def badopener(fname, flags):
903903
return -2
904904
with self.assertRaises(ValueError) as cm:
905-
open('non-existent', 'r', opener=badopener)
905+
self.open('non-existent', 'r', opener=badopener)
906906
self.assertEqual(str(cm.exception), 'opener returned -2')
907907

908908
def test_opener_invalid_fd(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Raise :exc:`ValueError` in :func:`open` if *opener* returns a negative
2+
file-descriptor in the Python implementation of :mod:`io` to match the
3+
C implementation.

0 commit comments

Comments
 (0)
0