-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[refactor] improve ConstantList exception specificity #22156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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): | ||||||
| raise Exception("Cannot insert into a constant list") | ||||||
| raise TypeError("Cannot insert into a constant list") | ||||||
|
|
||||||
| def pop(self, item): | ||||||
|
||||||
| def pop(self, item): | |
| def pop(self, index=-1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
insertmethod signature is incorrect. It should match thelist.insert(index, object)signature to correctly override the behavior and provide the intendedTypeError. The current signatureinsert(self, item)takes only one argument besidesself, which will cause aTypeErrorabout the number of arguments if a user tries to call it likelist.insert(0, value), preventing the intended "Cannot insert..." error from being raised.