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
Fix collections.UserList shallow copy #71328
Comments
I have encountered a weird behavior in collections.UserList. |
Please add a test case. |
What about UserDict? |
I thought about UserDict, but adding this simple patch to UserDict will result in infinite recursion (due to how copy is implemented in there). We will have to change the implementation of UserDict's copy method. |
Added UserDict and UserList tests. |
Are the patch and tests good? |
Yes. I will look at this shortly. |
UserList.copy() doesn't copy instance attributes, but copy.copy() should copy them. |
Alright. 2 patches are available. opt_1 makes the use of __copy__. Advantages:
Disadvantages:
opt_2 makes use of __reduce__. Advantages:
Disadvantages:
__getstate__ was not attempted as it will break backwards compatibility for sure if someone wrote a __reduce__ method (as it won't be called), but it's also a viable option. Both patches contain tests and both fix the bug in UserDict and UserList. |
I personally prefer the __copy__ mechanism as I think a bugfix shouldn't be 100000% backwards compatible, chances of issues are low, and it's cleaner, more efficient and how things should be. |
Bumposaurus Rex |
I prefer issue27141_patch_rev1_opt1.patch. But now we use GitHub. Do you mind to create a pull request Bar? |
Done :-) |
Either of the patches looks fine. I lean a bit towards the opt1 patch. |
Alrighty then, opt1 passed all tests and waiting on GitHub for inclusion :-) |
This seems complete, can it be closed? |
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: