Skip to content

Commit df6ec1d

Browse files
committed
Many changes from the new toolchain
1 parent 9ddd42c commit df6ec1d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

safer/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
# Either the whole file is written, or nothing
148148
149149
"""
150+
150151
from __future__ import annotations
151152

152153
import 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
602604
def _wrap_class(stream_cls):
603605
@functools.wraps(stream_cls.__exit__)
604606
def exit(self, *args):

test/test_open.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)