MCPcopy Index your code
hub / github.com/RustPython/RustPython / __setitem__

Method __setitem__

Lib/multiprocessing/shared_memory.py:451–482  ·  view source on GitHub ↗
(self, position, value)

Source from the content-addressed store, hash-verified

449 return v
450
451 def __setitem__(self, position, value):
452 position = position if position >= 0 else position + self._list_len
453 try:
454 item_offset = self._allocated_offsets[position]
455 offset = self._offset_data_start + item_offset
456 current_format = self._get_packing_format(position)
457 except IndexError:
458 raise IndexError("assignment index out of range")
459
460 if not isinstance(value, (str, bytes)):
461 new_format = self._types_mapping[type(value)]
462 encoded_value = value
463 else:
464 allocated_length = self._allocated_offsets[position + 1] - item_offset
465
466 encoded_value = (value.encode(_encoding)
467 if isinstance(value, str) else value)
468 if len(encoded_value) > allocated_length:
469 raise ValueError("bytes/str item exceeds available storage")
470 if current_format[-1] == "s":
471 new_format = current_format
472 else:
473 new_format = self._types_mapping[str] % (
474 allocated_length,
475 )
476
477 self._set_packing_format_and_transform(
478 position,
479 new_format,
480 value
481 )
482 struct.pack_into(new_format, self.shm.buf, offset, encoded_value)
483
484 def __reduce__(self):
485 return partial(self.__class__, name=self.shm.name), ()

Callers

nothing calls this directly

Calls 6

_get_packing_formatMethod · 0.95
isinstanceFunction · 0.85
lenFunction · 0.85
encodeMethod · 0.45
pack_intoMethod · 0.45

Tested by

no test coverage detected