def rename(self, key: Any, new_key: Any):
if new_key == key:<EOL><INDENT>return<EOL><DEDENT>required_locks = [self._key_locks[key], self._key_locks[new_key]]<EOL>ordered_required_locks = sorted(required_locks, key=lambda x: id(x))<EOL>for lock in ordered_required_locks:<EOL><INDENT>lock.acquire()<EOL><DEDENT>try:<EOL><INDENT>if key not in self._data:<EOL><INDENT>raise KeyError("<STR_LIT>" % key)<EOL><DEDENT>self._data[new_key] = self[key]<EOL>del self._data[key]<EOL><DEDENT>finally:<EOL><INDENT>for lock in required_locks:<EOL><INDENT>lock.release()<EOL><DEDENT><DEDENT>
Renames an item in this collection as a transaction.

Will override if new key name already exists.
:param key: the current name of the item
:param new_key: the new name that the item should have