Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions vllm/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ def __init__(self, x: list[T]) -> None:
self._x = x

def append(self, item):
raise Exception("Cannot append to a constant list")
raise TypeError("Cannot append to a constant list")

def extend(self, item):
raise Exception("Cannot extend a constant list")
raise TypeError("Cannot extend a constant list")

def insert(self, item):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The insert method signature is incorrect. It should match the list.insert(index, object) signature to correctly override the behavior and provide the intended TypeError. The current signature insert(self, item) takes only one argument besides self, which will cause a TypeError about the number of arguments if a user tries to call it like list.insert(0, value), preventing the intended "Cannot insert..." error from being raised.

Suggested change
def insert(self, item):
def insert(self, index, item):

raise Exception("Cannot insert into a constant list")
raise TypeError("Cannot insert into a constant list")

def pop(self, item):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pop method signature is incorrect. It should match list.pop([index]), which takes an optional index argument. The current signature pop(self, item) requires one argument, which is inconsistent with list.pop() that can be called with zero or one argument (the index). This will lead to unexpected TypeError exceptions related to arguments, rather than the intended one about immutability.

Suggested change
def pop(self, item):
def pop(self, index=-1):

raise Exception("Cannot pop from a constant list")
raise TypeError("Cannot pop from a constant list")

def remove(self, item):
raise Exception("Cannot remove from a constant list")
raise TypeError("Cannot remove from a constant list")

def clear(self):
raise Exception("Cannot clear a constant list")
raise TypeError("Cannot clear a constant list")

def index(self,
item: T,
Expand Down Expand Up @@ -78,10 +78,10 @@ def __setitem__(self, s: slice, value: T, /):
...

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

def __delitem__(self, item):
raise Exception("Cannot delete item from a constant list")
raise TypeError("Cannot delete item from a constant list")

def __iter__(self):
return iter(self._x)
Expand Down