Fix python generator bug