Skip to content

Commit 5f09cad

Browse files
committed
refactor: improve ConstantList exception specificity
Replace generic Exception with TypeError for all mutating operations in ConstantList class. This provides more precise error semantics as these operations attempt to modify an immutable data structure, which is fundamentally a type compatibility issue. Changes: - append, extend, insert, pop, remove, clear methods - __setitem__ and __delitem__ magic methods This improves error handling precision and follows Python best practices for exception types. Signed-off-by: zitian.zhao <zitian.zhao@tencentmusic.com>
1 parent d3c18c9 commit 5f09cad

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

vllm/v1/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ def __init__(self, x: list[T]) -> None:
3434
self._x = x
3535

3636
def append(self, item):
37-
raise Exception("Cannot append to a constant list")
37+
raise TypeError("Cannot append to a constant list")
3838

3939
def extend(self, item):
40-
raise Exception("Cannot extend a constant list")
40+
raise TypeError("Cannot extend a constant list")
4141

4242
def insert(self, item):
43-
raise Exception("Cannot insert into a constant list")
43+
raise TypeError("Cannot insert into a constant list")
4444

4545
def pop(self, item):
46-
raise Exception("Cannot pop from a constant list")
46+
raise TypeError("Cannot pop from a constant list")
4747

4848
def remove(self, item):
49-
raise Exception("Cannot remove from a constant list")
49+
raise TypeError("Cannot remove from a constant list")
5050

5151
def clear(self):
52-
raise Exception("Cannot clear a constant list")
52+
raise TypeError("Cannot clear a constant list")
5353

5454
def index(self,
5555
item: T,
@@ -78,10 +78,10 @@ def __setitem__(self, s: slice, value: T, /):
7878
...
7979

8080
def __setitem__(self, item: Union[int, slice], value: Union[T, list[T]]):
81-
raise Exception("Cannot set item in a constant list")
81+
raise TypeError("Cannot set item in a constant list")
8282

8383
def __delitem__(self, item):
84-
raise Exception("Cannot delete item from a constant list")
84+
raise TypeError("Cannot delete item from a constant list")
8585

8686
def __iter__(self):
8787
return iter(self._x)

0 commit comments

Comments
 (0)