File tree 3 files changed +15
-6
lines changed
3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ Fixed regressions
30
30
31
31
Bug fixes
32
32
~~~~~~~~~
33
- -
33
+ - Most I/O methods do no longer suppress `` OSError `` and `` ValueError `` when closing file handles ( :issue: ` 47136 `)
34
34
-
35
35
36
36
.. ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -115,11 +115,8 @@ def close(self) -> None:
115
115
self .handle .flush ()
116
116
self .handle .detach ()
117
117
self .created_handles .remove (self .handle )
118
- try :
119
- for handle in self .created_handles :
120
- handle .close ()
121
- except (OSError , ValueError ):
122
- pass
118
+ for handle in self .created_handles :
119
+ handle .close ()
123
120
self .created_handles = []
124
121
self .is_wrapped = False
125
122
Original file line number Diff line number Diff line change @@ -592,3 +592,15 @@ def test_fail_mmap():
592
592
with pytest .raises (UnsupportedOperation , match = "fileno" ):
593
593
with BytesIO () as buffer :
594
594
icom .get_handle (buffer , "rb" , memory_map = True )
595
+
596
+
597
+ def test_close_on_error ():
598
+ # GH 47136
599
+ class TestError :
600
+ def close (self ):
601
+ raise OSError ("test" )
602
+
603
+ with pytest .raises (OSError , match = "test" ):
604
+ with BytesIO () as buffer :
605
+ with icom .get_handle (buffer , "rb" ) as handles :
606
+ handles .created_handles .append (TestError ())
You can’t perform that action at this time.
0 commit comments