规范报错

This commit is contained in:
moyan 2024-05-07 16:41:35 +08:00
parent c8af031c83
commit 13047c2443

View File

@ -12,15 +12,15 @@ class Memory:
def __getitem__(self, key: int):
if key > self.size:
raise AddressError
raise AddressError(key)
return self.data[key]
def write(self, index: int, val: int):
if index > self.size:
raise AddressError()
raise AddressError(index)
self.data[index] = val
def write_batch(self, start, dt: list[int]):
def write_batch(self, start, dt):
if start + len(dt) > self.size:
raise OutOfMemory("内存用尽")
@ -46,12 +46,12 @@ class Memory:
stop = k.stop
if start > self.size or stop > self.size:
raise AddressError
raise AddressError(start)
self.data[start:stop] = v
return
if k > self.size:
raise AddressError
raise AddressError(k)
self.data[k] = v
return