Serhiy Storchaka added the comment: The weakref.proxy object delegates all attribute access to referred object, including special attributes used in pickling, like __class__ or __getstate__.
test.recursive is not test, but it looks as TestPickle instance for the pickler. It is pickled and unpickled as TestPickle instance. >>> test.recursive.__class__ <class '__main__.TestPickle'> >>> test.recursive.__getstate__ <bound method TestPickle.__getstate__ of <__main__.TestPickle object at 0xb7130bac>> >>> test.recursive.__reduce_ex__(2) __getstate__ 3071478700 (<function __newobj__ at 0xb74b76f4>, (<class '__main__.TestPickle'>,), {'recursive': <weakproxy at 0xb7127a04 to TestPickle at 0xb7130bac>}, None, None) >>> pickle.loads(pickle.dumps(test.recursive, 2)) __getstate__ 3071478700 __setstate__ 3071525356 <__main__.TestPickle object at 0xb713c1ec> Since test.recursive.recursive is test.recursive, this recursion is detected by pickler. This issue is similar to issue6395, but since weakref.proxy is not subclassable, we can just implement correct __reduce__. ---------- assignee: -> serhiy.storchaka nosy: +serhiy.storchaka stage: -> needs patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18068> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com