Łukasz Langa added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue16251>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to