This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bar.harel
Recipients bar.harel, pakal, rhettinger, serhiy.storchaka
Date 2016-09-26.18:32:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474914737.38.0.325136461925.issue27141@psf.upfronthosting.co.za>
In-reply-to
Content
Alright. 2 patches are available.

opt_1 makes the use of __copy__.

Advantages:

- Clean
- Does not affect pickling at all
- More memory efficient

Disadvantages:

- Might be missing something from the normal copy mechanism (e.g. UserList doesn't implement __slots__ but it somewhat interferes with future implementation)
- Doesn't call __reduce__, __getstate__, ... while people might rely on it for some reason during copy, thus it might not be entirely backwards compatible

opt_2 makes use of __reduce__.

Advantages:

- Lowest in the chain. Shouldn't cause any backwards compatibility issues as if the user manually defined __getstate__ or __reduce_ex__ himself, the code as far as he's concerned did not change.
- Uses the default mechanism for copying. Changes in the protocol will not cause any bug in here.

Disadvantages:

- Affects pickling, messes up with the __reduce__ protocol.
- Takes more memory during pickling as it recreates the dict.
- Uglier as a personal opinion.

__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.
History
Date User Action Args
2016-09-26 18:32:17bar.harelsetrecipients: + bar.harel, rhettinger, pakal, serhiy.storchaka
2016-09-26 18:32:17bar.harelsetmessageid: <1474914737.38.0.325136461925.issue27141@psf.upfronthosting.co.za>
2016-09-26 18:32:17bar.harellinkissue27141 messages
2016-09-26 18:32:17bar.harelcreate