Count the number of distinct genes in model reactions.

def count_genes(model):
    """Count the number of distinct genes in model reactions."""
    genes = set()
    for reaction in model.reactions:
        if reaction.genes is None:
            continue

        if isinstance(reaction.genes, boolean.Expression):
            genes.update(v.symbol for v in reaction.genes.variables)
        else:
            genes.update(reaction.genes)

    return len(genes)