class_docstr: This class performs the mapping between the objects contained
  in a HDF5 group and Dataset attributes.
class_docstr_tok: ["This","class","performs","the","mapping","between","the","objects","contained","in","a","HDF5","group","and","Dataset","attributes","."]
docstr: Creates or replaces attribute ``key`` with ``value``, optionally
  including ``info``.
  
  Args:
      key: Name of attribute in HDF5 group
      value: Attribute value, either a compatible object or an already
          initialized ``DatasetAttribute``.
      info: Extra info to attach to attribute
      require_type: Force the ``value`` to be serialized as this type.
          If ``value`` is an ``DatasetAttribute``, it must be an instance of ``require_type``.
          Otherwise, ``value`` must be serializable by ``require_type``.
docstr_tok: ["Creates","or","replaces","attribute","``","key","``","with","``","value","``",",","optionally","including","``","info","``",".","Args",":","key",":","Name","of","attribute","in","HDF5","group","value",":","Attribute","value",",","either","a","compatible","object","or","an","already","initialized","``","DatasetAttribute","``",".","info",":","Extra","info","to","attach","to","attribute","require_type",":","Force","the","``","value","``","to","be","serialized","as","this","type",".","If","``","value","``","is","an","``","DatasetAttribute","``",",","it","must","be","an","instance","of","``","require_type","``",".","Otherwise",",","``","value","``","must","be","serializable","by","``","require_type","``","."]
code: def set_item(
      self,
      key: str,
      value: Any,
      info: Optional[AttributeInfo],
      require_type: Optional[Type[DatasetAttribute]] = None,
  ) -> None:
      """Creates or replaces attribute ``key`` with ``value``, optionally
      including ``info``.
  
      Args:
          key: Name of attribute in HDF5 group
          value: Attribute value, either a compatible object or an already
              initialized ``DatasetAttribute``.
          info: Extra info to attach to attribute
          require_type: Force the ``value`` to be serialized as this type.
              If ``value`` is an ``DatasetAttribute``, it must be an instance of ``require_type``.
              Otherwise, ``value`` must be serializable by ``require_type``.
      """
      try:
          if isinstance(value, DatasetAttribute):
              if require_type and not isinstance(value, require_type):
                  raise TypeError(
                      f"Expected '{key}' to be of type '{require_type.__name__}', but got '{type(value).__name__}'."
                  )
  
              value._set_parent(
                  self.bind, key
              )  # pylint: disable=protected-access
              if info:
                  info.save(value.info)
  
          elif require_type is not None:
              require_type(value, info, parent_and_key=(self.bind, key))
          else:
              attr_type = match_obj_type(value)
              attr_type(value, info, parent_and_key=(self.bind, key))
      except ValueError as exc:
          if (
              exc.args[0]
              == "Unable to create dataset (no write intent on file)"
          ):
              raise DatasetNotWriteableError(self.bind) from exc
  
          raise exc
  
      self._cache.pop(key, None)
  
imports: import typing
  from collections.abc import MutableMapping
  from types import MappingProxyType
  from typing import Any, Dict, Optional, Type
  from pennylane.data.base.attribute import AttributeInfo, DatasetAttribute, get_attribute_type, match_obj_type
  from pennylane.data.base.hdf5 import HDF5Any, HDF5Group
label_desc: Use image node_id 4 for calling the AttributeTypeMapper obj's underlying member method code with example usage: obj.set_item(key, value, info, require_type) without return types