Message301989
> These two classes obviously are not pickleable. Pickling or copying them is a programming error.
The recursion case was successfully deep copying under Python 2. When migrating the code, the sudden recursion error is pretty hard to debug.
> I believe the proper way of making them pickleable and copyable is implementing corresponding special methods.
Right, but during migration from Python 2 to Python 3 the error message is nowhere close suggesting what the correct behavior is.
>> Can you give me an example where this would lead to incorrect pickle data?
> Any class that needs non-trivial __getstate__().
My patch doesn't change anything here. It simply causes special methods to be reported as not present instead of raising exceptions from within __getattr__.
> hasattr() is broken in Python 2. It was fixed in Python 3.
Yes, I agree.
> Your patch reintroduces similar bug in copy.
No, my patch introduces a getattr() equivalent for deepcopy which is robust against random exceptions raised from __getattr__.
------------
Let's take a step back. My goal with this patch is two-fold:
* make code that worked on Python 2 (even if clowny) not fail on Python 3, adding to the migration burden;
* make a change that is not changing semantics of the current behavior to not break existing code deliberately putting magic methods on instances (hence I'm not switching to the right behavior to test presence of magic methdos on types instead).
Clearly the current workaround I wrote doesn't go in the direction you'd like to see. Do you have a suggestion of an approach that would be better? I can implement it. |
|
Date |
User |
Action |
Args |
2017-09-12 18:34:17 | lukasz.langa | set | recipients:
+ lukasz.langa, barry, rhettinger, pitrou, benjamin.peterson, hodgestar, Arfrever, python-dev, eric.snow, serhiy.storchaka, robagar |
2017-09-12 18:34:17 | lukasz.langa | set | messageid: <1505241257.05.0.254795521521.issue16251@psf.upfronthosting.co.za> |
2017-09-12 18:34:17 | lukasz.langa | link | issue16251 messages |
2017-09-12 18:34:16 | lukasz.langa | create | |
|