Serhiy Storchaka added the comment:

There are many ways to pickle e.g. Mapping keys:

1) Default implementation (as an instances of Python class MappingKey). This is 
implementation depended and exposes private variable _mapping. Changing 
implementation of the keys() method will break compatibility.

2) As `self.__class__, (self._mapping,)`. It depends on implementation of 
keys() as MappingKey or MappingKey subclass. It doesn't very subclass friendly 
if keys() is more complex or MappingKey subclass requires additional parameters.

3) As `self._mapping.__class__.keys, (self._mapping,)`. Implementation 
agnostic, perhaps more efficient than option 4 because 
self._mapping.__class__.keys may be shared. But needs protocol 4.

4) As `self._mapping.keys, ()`. Implementation agnostic.

pickle_mapping_views.patch implements option 4, the patch in issue23264 
implements option 3 (it works for dict with all protocols, but needs protocol 4 
for dict subclasses). Perhaps implementations should be unified (use option 3 
with protocol 4 and option 3 otherwise).

----------

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

Reply via email to