Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06eaf40

Browse filesBrowse files
gh-71253: Match _io exception in _pyio (gh-133985)
Test was only testing _io, expanded to cover _pyio. Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 84d5f8d commit 06eaf40
Copy full SHA for 06eaf40

File tree

Expand file treeCollapse file tree

3 files changed

+7
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+7
-3
lines changed

‎Lib/_pyio.py

Copy file name to clipboardExpand all lines: Lib/_pyio.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,8 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
15631563
if not isinstance(fd, int):
15641564
raise TypeError('expected integer from opener')
15651565
if fd < 0:
1566-
raise OSError('Negative file descriptor')
1566+
# bpo-27066: Raise a ValueError for bad value.
1567+
raise ValueError(f'opener returned {fd}')
15671568
owned_fd = fd
15681569
if not noinherit_flag:
15691570
os.set_inheritable(fd, False)

‎Lib/test/test_io.py

Copy file name to clipboardExpand all lines: Lib/test/test_io.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,15 +918,15 @@ def test_bad_opener_negative_1(self):
918918
def badopener(fname, flags):
919919
return -1
920920
with self.assertRaises(ValueError) as cm:
921-
open('non-existent', 'r', opener=badopener)
921+
self.open('non-existent', 'r', opener=badopener)
922922
self.assertEqual(str(cm.exception), 'opener returned -1')
923923

924924
def test_bad_opener_other_negative(self):
925925
# Issue #27066.
926926
def badopener(fname, flags):
927927
return -2
928928
with self.assertRaises(ValueError) as cm:
929-
open('non-existent', 'r', opener=badopener)
929+
self.open('non-existent', 'r', opener=badopener)
930930
self.assertEqual(str(cm.exception), 'opener returned -2')
931931

932932
def test_opener_invalid_fd(self):
+3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.