code: def as_policy(cls, obj):
          
          if obj is None:
              # Use default policy.
              return TaskPolicy()
          else:
              if isinstance(obj, cls):
                  return obj
              elif isinstance(obj, collections.abc.Mapping):
                  return cls(**obj)
              else:
                  raise TypeError("Don't know how to convert type %s to %s" % (type(obj), cls))
docs: Converts an object obj into a `:class:`TaskPolicy. Accepts:
  
              * None
              * TaskPolicy
              * dict-like object