def to_arbitrary(obj):
    if inspect.isgenerator(obj):
        return obj
    if inspect.isgeneratorfunction(obj):
        return obj()    # fails if arguments are required,
                        # and this is intended

    # looking up types in global registry
    if isinstance(obj, type):
        arbit_gens = arbitrary.registry.get(obj)
        if not arbit_gens:
            raise TypeError(
                "no arbitrary values' generator found for type: %s" % obj)
        return to_arbitrary(arbit_gens[0])

    raise ValueError(
        "invalid generator of arbitrary values: %r (of type %s)" % (
            obj, type(obj).__name__))
Ensures that given object is a generator of arbitrary values.
dataset/ETHPy150Open Xion/pyqcy/pyqcy/arbitraries/__init__.py/to_arbitrary