@staticmethod
def rename_key(old_key, new_key, commented_map, logger=None):
    """Rename a key in YAML file data that was loaded with the RoundTripLoader (e.g. that contains comments).

        Comments are retained for the renamed key. Order of keys is also maintained.

        Args:
            old_key: The existing key name you want to change.
            new_key: The new key name.
            commented_map: The YAML data CommentMap class (from yaml.load) with
                the key you want to change.
            logger: Optional logger instance which will be used to log this at
                the debug level.

        Returns the updated CommentedMap YAML dict. (Note that this method does not
        change the dict object (e.g. it's changed in place), you you most
        likely don't need to do anything with the returned dict.
        """
    if old_key == new_key or old_key not in commented_map:
        return commented_map
    key_list = list(commented_map.keys())
    for key in key_list:
        if key == old_key:
            if logger:
                logger.debug('Renaming key: %s: -> %s:', old_key, new_key)
            commented_map[new_key] = commented_map[old_key]
            try:
                commented_map.ca.items[new_key] = commented_map.ca.items.pop(
                    old_key)
            except KeyError:
                pass
            del commented_map[old_key]
        else:
            commented_map.move_to_end(key)
    return commented_map
