File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 147147 # Either the whole file is written, or nothing
148148
149149"""
150+
150151from __future__ import annotations
151152
152153import contextlib
@@ -253,6 +254,7 @@ def writer(
253254 raise NotImplementedError (BUG_MESSAGE )
254255
255256 def write (v ):
257+ assert isinstance (stream , t .ContextManager ), (stream , type (stream ))
256258 with stream :
257259 stream .write (v )
258260
@@ -399,7 +401,7 @@ def open(
399401 parent = os .path .dirname (os .path .abspath (name ))
400402 if not os .path .exists (parent ):
401403 if not make_parents :
402- raise IOError ('Directory does not exist' )
404+ raise OSError ('Directory does not exist' )
403405 os .makedirs (parent )
404406
405407 def simple_open ():
@@ -552,7 +554,7 @@ def printer(
552554 Same as for `safer.open()`
553555 """
554556 if 'r' in mode and '+' not in mode :
555- raise IOError ('File not open for writing' )
557+ raise OSError ('File not open for writing' )
556558
557559 if 'b' in mode :
558560 raise ValueError ('Cannot print to a file open in binary mode' )
@@ -598,7 +600,7 @@ def wrapped(*args, **kwargs):
598600
599601
600602# Wrap an existing IO class so that it calls safer at the end
601- @functools .lru_cache ()
603+ @functools .lru_cache
602604def _wrap_class (stream_cls ):
603605 @functools .wraps (stream_cls .__exit__ )
604606 def exit (self , * args ):
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ def test_file_perms(self, safer_open):
153153 elif os .name == 'nt' :
154154 new_mode = mode
155155 else :
156- assert False , f'Do not understand os.name = { os .name } '
156+ raise ValueError ( f'Do not understand os.name = { os .name } ' )
157157
158158 os .chmod (FILENAME , new_mode )
159159 with safer_open (FILENAME , 'w' ) as fp :
You can’t perform that action at this time.
0 commit comments