def apply(self, fn: Callable[[InventoryType], InventoryType]) -> None:
    """Apply `function` to `args` and update the inventory accordingly."""
    with self._lock:
      old_inventories = copy.deepcopy(self._inventories)
      new_inventories = fn(old_inventories)
      if set(new_inventories.keys()) != set(old_inventories.keys()):
        raise RuntimeError(
            'New inventory keys do not match old inventory keys.'
        )
      for item_type, config in self._item_types_dict.items():
        for key in new_inventories:
          missing = set(self._item_types_dict) - set(new_inventories[key])
          if missing:
            raise RuntimeError(f'{key} inventory missing {missing} types.')
          invalid = set(new_inventories[key]) - set(self._item_types_dict)
          if invalid:
            raise RuntimeError(f'{key} inventory has invalid {invalid} types.')
          config.check_valid(new_inventories[key][item_type])
      self._inventories = copy.deepcopy(new_inventories)
Apply `function` to `args` and update the inventory accordingly.
concordia/components/game_master/deprecated/inventory.py