-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
crash in methods of a subclass of _collections.deque with a bad __new__() #75789
Comments
The following code causes the interpreter to crash: import _collections
class BadDeque(_collections.deque):
def __new__(cls, *args):
if len(args):
return 42
return _collections.deque.__new__(cls) BadDeque() * 42 (The interpreter would crash also if we replaced 'BadDeque() * 42' with This is because deque_copy() (in Modules/_collectionsmodule.c) returns whatever (Similarly, deque_concat() assumes that deque_copy() returned a deque, which ISTM it is a very unlikely corner case, so that adding a test (as well as |
All other sequence objects return an instance of the base class rather than a subclass. list, tuple, str, bytes, bytearray, array. Only deque tries to create an instance of a subclass. |
I meant that if make deque.copy(), deque.__add__() and deque.__mul__() returning an exact deque for subclasses, this would make the deque class more consistent with other collections and solve this issue. This could even make them (almost) atomic. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: