规范报错
This commit is contained in:
parent
c8af031c83
commit
13047c2443
10
Memory.py
10
Memory.py
|
@ -12,15 +12,15 @@ class Memory:
|
||||||
|
|
||||||
def __getitem__(self, key: int):
|
def __getitem__(self, key: int):
|
||||||
if key > self.size:
|
if key > self.size:
|
||||||
raise AddressError
|
raise AddressError(key)
|
||||||
return self.data[key]
|
return self.data[key]
|
||||||
|
|
||||||
def write(self, index: int, val: int):
|
def write(self, index: int, val: int):
|
||||||
if index > self.size:
|
if index > self.size:
|
||||||
raise AddressError()
|
raise AddressError(index)
|
||||||
self.data[index] = val
|
self.data[index] = val
|
||||||
|
|
||||||
def write_batch(self, start, dt: list[int]):
|
def write_batch(self, start, dt):
|
||||||
if start + len(dt) > self.size:
|
if start + len(dt) > self.size:
|
||||||
raise OutOfMemory("内存用尽")
|
raise OutOfMemory("内存用尽")
|
||||||
|
|
||||||
|
@ -46,12 +46,12 @@ class Memory:
|
||||||
stop = k.stop
|
stop = k.stop
|
||||||
|
|
||||||
if start > self.size or stop > self.size:
|
if start > self.size or stop > self.size:
|
||||||
raise AddressError
|
raise AddressError(start)
|
||||||
|
|
||||||
self.data[start:stop] = v
|
self.data[start:stop] = v
|
||||||
return
|
return
|
||||||
|
|
||||||
if k > self.size:
|
if k > self.size:
|
||||||
raise AddressError
|
raise AddressError(k)
|
||||||
self.data[k] = v
|
self.data[k] = v
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user