@@ -147,6 +147,7 @@
|
147 | 147 | # Either the whole file is written, or nothing |
148 | 148 | |
149 | 149 | """ |
| 150 | + |
150 | 151 | from __future__ import annotations |
151 | 152 | |
152 | 153 | import contextlib |
@@ -253,6 +254,7 @@ def writer(
|
253 | 254 | raise NotImplementedError(BUG_MESSAGE) |
254 | 255 | |
255 | 256 | def write(v): |
| 257 | +assert isinstance(stream, t.ContextManager), (stream, type(stream)) |
256 | 258 | with stream: |
257 | 259 | stream.write(v) |
258 | 260 | |
@@ -399,7 +401,7 @@ def open(
|
399 | 401 | parent = os.path.dirname(os.path.abspath(name)) |
400 | 402 | if not os.path.exists(parent): |
401 | 403 | if not make_parents: |
402 | | -raise IOError('Directory does not exist') |
| 404 | +raise OSError('Directory does not exist') |
403 | 405 | os.makedirs(parent) |
404 | 406 | |
405 | 407 | def simple_open(): |
@@ -552,7 +554,7 @@ def printer(
|
552 | 554 | Same as for `safer.open()` |
553 | 555 | """ |
554 | 556 | if 'r' in mode and '+' not in mode: |
555 | | -raise IOError('File not open for writing') |
| 557 | +raise OSError('File not open for writing') |
556 | 558 | |
557 | 559 | if 'b' in mode: |
558 | 560 | raise ValueError('Cannot print to a file open in binary mode') |
@@ -598,7 +600,7 @@ def wrapped(*args, **kwargs):
|
598 | 600 | |
599 | 601 | |
600 | 602 | # Wrap an existing IO class so that it calls safer at the end |
601 | | -@functools.lru_cache() |
| 603 | +@functools.lru_cache |
602 | 604 | def _wrap_class(stream_cls): |
603 | 605 | @functools.wraps(stream_cls.__exit__) |
604 | 606 | def exit(self, *args): |
|