Could you extract this block into a method e.g. `io = io_from_path_or_io(path_or_io)`