<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def remove_device(self, device: Union[DeviceType, str]) -> None: """Remove the given |Node| or |Element| object from the actual |Nodes| or |Elements| object. You can pass either a string or a device: Nodes("node_x") Nodes() Traceback (most recent call last):
 ValueError: While trying to remove the device `node_z` from a \ Nodes object, the following error occurred: The actual Nodes object does \ not handle such a device. Method |Devices.remove_device| is disabled for immutable |Nodes| and |Elements| objects: Traceback (most recent call last):
 RuntimeError: While trying to remove the device `node_z` from a \ Nodes object, the following error occurred: Removing devices from \ immutable Nodes objects is not allowed. """

        try:
            if self.mutable:
                _device = self.get_contentclass()(device)
                try:
                    del self._name2device[_device.name]
                except KeyError:
                    raise ValueError(
                        f'The actual {objecttools.classname(self)} '
                        f'object does not handle such a device.')
                del _id2devices[_device][id(self)]
            else:
                raise RuntimeError(
                    f'Removing devices from immutable '
                    f'{objecttools.classname(self)} objects is not allowed.')
        except BaseException:
            objecttools.augment_excmessage(
                f'While trying to remove the device `{device}` from a '
                f'{objecttools.classname(self)} object')