import gzip


def open_maybe_compressed_file(path):
    """Return a file object that possibly decompresses 'path' on the fly.
       Decompression occurs when argument `path` is a string and ends with '.gz'.
    """
    if path.endswith(".gz"):
        return gzip.open(path, "rb")
    else:
        return open(path, "rb")