def attr_superclass(type_, subname=''):
  """An `attr.s` validator for asserting the superclass of a value.

  Args:
    * type_ (object) - The python type object to validate `value` is a subclass
      of.
    * subname (str) - Some sub-element of attrib.name; e.g. if checking
      a dictionary key, this might be ' keys'.

  Returns a validator function which raises TypeError if the value doesn't match
  the value.
  """

  def inner(_self, attrib, value):
    if not issubclass(type(value), type_):
      raise TypeError(
        "'{name}' must be a subclass of {type!r} (got {value!r} that is a "
        "{actual!r}).".format(
          name=attrib.name+subname,
          type=type_,
          actual=value.__class__,
          value=value,
        ),
        attrib,
        value,
        type_,
        subname,
      )
  return inner