{"record":{"id":"8225afa7790e0f72","repo":"Lightning-AI/pytorch-lightning","slug":"setitem-is-not-supported","errorCode":null,"errorMessage":"__setitem__ is not supported","messagePattern":"__setitem__ is not supported","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"warning","filePath":"src/lightning/fabric/utilities/throughput.py","lineNumber":719,"sourceCode":"    def last(self) -> Optional[T]:\n        if len(self) > 0:\n            return self[-1]\n        return None\n\n    @override\n    def append(self, x: T) -> None:\n        last = self.last\n        if last is not None and last >= x:\n            raise ValueError(f\"Expected the value to increase, last: {last}, current: {x}\")\n        list.append(self, x)\n        # truncate excess\n        if len(self) > self.maxlen:\n            del self[0]\n\n    @override\n    def __setitem__(self, key: Any, value: Any) -> None:\n        # assigning is not implemented since we don't use it. it could be by checking all previous values\n        raise NotImplementedError(\"__setitem__ is not supported\")\n","sourceCodeStart":701,"sourceCodeEnd":720,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/throughput.py#L701-L720","documentation":"_Monotonic overrides list to enforce strictly increasing values; item assignment cannot be validated cheaply, so __setitem__ deliberately raises NotImplementedError. Users are meant to only append values, never mutate history.","triggerScenarios":"Directly indexing the internal list used by ThroughputMonitor (e.g. monitor._elapsed_interval[i] = value) or any code that treats the container as a plain list and assigns by index or slice.","commonSituations":"Test helpers or monkeypatching that try to rewrite recorded values; copy/deepcopy or serialization code that repopulates via item assignment rather than append; debugging code that edits history.","solutions":["Rebuild the container by appending values in increasing order instead of assigning by index","If you need a mutable history, copy the values into a plain list: list(monitor._elapsed_interval)","Avoid touching private attributes prefixed with underscore"],"exampleFix":"# before\nmonitor._elapsed_interval[0] = 1.0\n\n# after\nvalues = sorted(list(monitor._elapsed_interval))\nvalues[0] = 1.0\nnew_list = _Monotonic(maxlen=len(values))\nfor v in sorted(values):\n    new_list.append(v)","handlingStrategy":"validation","validationCode":"# nothing to validate: simply never assign into the container\nvalues = list(monotonic_list)  # copy out if you need to edit","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat _Monotonic as append-only","Do not touch underscore-prefixed attributes of ThroughputMonitor"],"tags":["pytorch-lightning","not-implemented","internal-api"],"backgroundTag":"unsupported-operation","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}