def __setitem__(self, key, value):
<EOL>try:<EOL><INDENT>int(key)<EOL><DEDENT>except TypeError:<EOL><INDENT>key_is_int = False<EOL><DEDENT>else:<EOL><INDENT>key_is_int = True<EOL>if key < <NUM_LIT:0>:<EOL><INDENT>key += len(self)<EOL><DEDENT>key = slice(key, key + <NUM_LIT:1>)<EOL><DEDENT>start = key.start or <NUM_LIT:0><EOL>if start < <NUM_LIT:0>:<EOL><INDENT>start += len(self)<EOL><DEDENT>if start >= len(self):<EOL><INDENT>raise IndexError('<STR_LIT>'.format(self.__class__.__name__))<EOL><DEDENT>stop = key.stop or (start if key.stop == <NUM_LIT:0> else len(self))<EOL>if stop < <NUM_LIT:0>:<EOL><INDENT>stop += len(self)<EOL><DEDENT>start += self.slice.start<EOL>stop += self.slice.start<EOL>stop = min(stop, self.slice.stop)<EOL>original_length = len(self.pointee)<EOL>if not key_is_int and len(self.pointee[start:stop]) != len(value):<EOL><INDENT>raise TypeError("<STR_LIT>".format(self.__class__.__name__))<EOL><DEDENT>if key_is_int:<EOL><INDENT>self.pointee[start] = value<EOL><DEDENT>else:<EOL><INDENT>self.pointee[start:stop] = value<EOL><DEDENT>if len(self.pointee) != original_length:<EOL><INDENT>raise RuntimeError('<STR_LIT>'.format(self.__class__.__name__))<EOL><DEDENT>
Set value in the correct index of the parent bytearray.