This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients gregory.p.smith, richardlev, serhiy.storchaka
Date 2021-04-27.05:29:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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__.
Date User Action Args
2021-04-27 05:29:40serhiy.storchakasetrecipients: + serhiy.storchaka, gregory.p.smith, richardlev
2021-04-27 05:29:40serhiy.storchakasetmessageid: <>
2021-04-27 05:29:40serhiy.storchakalinkissue43946 messages
2021-04-27 05:29:40serhiy.storchakacreate