This can't be an ifdef. Either it benefits all systems, or none at all. As uPy is intended to be a small implementation, many error checks are [still] omitted. So, please either help to make uPy, not just your port, more robust, or just don't read from closed files ;-).