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
calling MutableSequence.extend on self produces infinite loop #78608
Comments
Example:
|
I forgot to copy over __len__ in the example |
It would be reasonable to add special handling for this case to match what is done in the concrete sequences like list, deque, bytes, ... |
deque and bytearray make an in-memory copy of self if extended with self. deque creates a temporary list, bytearray creates a temporary bytearray. list just iterates itself as a linear array of known size and avoids infinite loop. It could be possible to avoid creaing a temporary copy in case of deque and bytearray too, but I don't think this special case is worth an additional code. But a MutableSequence can represents a sequence that doesn't fit in memory. It can provide an interface to a linear on-disk store. In this case creating an on-memory copy is not possible. |
This case is likely not worth worrying about. If a user created such a sequence AND wrote "s += s", it is unclear whether any particular unpleasant outcome (including the current behavior) could be avoided. |
Agreed. Appending >2**31 items one by one to the collection with external storage is not very efficient, so such collection likely has specialized extend(). |
Thank you for the patch. |
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: