Exercise 1: Reading an Unmounted Path Fails Clearly, Not Silently — Possible Solution ==================================================================== THE TEST ------------------------------ vfs.mount('/real', DiskBackend(num_bytes=64)) vfs.write('/real', 0, b'DATA') vfs.read('/nonexistent', 0, 4) # a path that was never mounted RESULT ------------------------------ reading an unmounted path '/nonexistent' raised: KeyError('/nonexistent') the genuinely mounted path still reads correctly afterward: b'DATA' A real, immediate KeyError -- and the already-working mount is completely unaffected afterward. WHY THE ERROR IS IMMEDIATE AND CLEAR ------------------------------ VFS.read() and VFS.write() are both single-line lookups: def read(self, path, offset, length): return self.mounts[path].read(offset, length) self.mounts is a plain Python dict, and self.mounts[path] on a key that was never inserted raises a real KeyError immediately -- there's no fallback, no default value, no silent no-op path anywhere in this implementation. WHY THIS DISTINCTION MATTERS ------------------------------ A VFS that silently returned b'' (empty bytes) for an unmounted path would be genuinely dangerous: a caller reading from a path it mistakenly believes is mounted (a typo, a path constructed incorrectly, a mount that failed earlier without the caller noticing) would get back a value that's INDISTINGUISHABLE from "the file genuinely exists and happens to be empty." That's a real, silent data- integrity risk -- code downstream might proceed as if it successfully read a real (if empty) file, when actually nothing was ever read at all. A real, loud KeyError instead forces the caller to confront the mistake immediately, at the exact point it happened, rather than propagating a subtly wrong assumption further into the system. WHY THIS WORKS AS AN ANSWER ------------------------------ Confirming BOTH that the unmounted read fails AND that the genuinely mounted path still works correctly afterward rules out the possibility that the failed lookup somehow corrupted the VFS's own internal state -- the dict-based mounts table is exactly as straightforward as it looks, with a failed key lookup on one path having zero effect on any other.