Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

>From PEP 307:

    listitems    Optional, and new in this PEP.
                 If this is not None, it should be an iterator (not a
                 sequence!) yielding successive list items.  These list
                 items will be pickled, and appended to the object using
                 either obj.append(item) or obj.extend(list_of_items).
                 This is primarily used for list subclasses, but may
                 be used by other classes as long as they have append()
                 and extend() methods with the appropriate signature.
                 (Whether append() or extend() is used depends on which
                 pickle protocol version is used as well as the number
                 of items to append, so both must be supported.)

It says that obj.extend(list_of_items) should be called, not list.extend(obj, 
list_of_items). Changing it now can break classes which rely on overridden 
extend(). The special check in the C code is only for optimization, we can 
inline extend() if it was not overridden.

Unfortunately __setstate__() is called after extend(), so there is no way to 
set the validator in FieldList before it will be used in extend().

As a clever hack (if you do not want to do runtime check in every call of 
extend()) you can set

    self.extend = lambda items: list.extend(self, items)

in the __new__ method and add

    del self.extend

in __init__ and __setstate__.

----------

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

Reply via email to