[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-05-18 Thread Pierre Glaser
Change by Pierre Glaser : -- stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See also issue26579 which propose to add a function or method for standard implementation of __getstate__ and use it consistently in custom __getstate__ implementations. I am not sure about API yet. -- ___

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-20 Thread Pierre Glaser
Pierre Glaser added the comment: I added a PR with a small patch to document this behavior and reconcile _pickle.c and pickle.py Some explanations on why I am pushing this forward: Pickling instances of classes/subclasses with slots is done natively for pickle protocol >= 2. Mentioning

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: A slotted class will have a dict also when it inherits it from a non-slotted class. This is why the base class of slotted class should have slots if you do not want an instance dict. __getstate__ and __setstate__ for slotted classes are described in PEP

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-20 Thread Pierre Glaser
Change by Pierre Glaser : -- keywords: +patch pull_requests: +11981 stage: -> patch review ___ Python tracker ___ ___

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-08 Thread Pierre Glaser
Change by Pierre Glaser : Added file: https://bugs.python.org/file48114/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-08 Thread Pierre Glaser
Change by Pierre Glaser : Removed file: https://bugs.python.org/file48113/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-08 Thread Pierre Glaser
Pierre Glaser added the comment: Thanks Antoine and Raymond for the feedback. Indeed, a subclass of a slotted class can have a dict: I enriched the script, pickling_depickling instances of such subclasses, with the length-2 tuple __getstate__ method, and made sure their attributes were

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Raymond Hettinger
Raymond Hettinger added the comment: Interestingly, you can also put an instance dict in slots: >>> class A: __slots__ = ['x', '__dict__'] >>> a = A() >>> a.x = 5 >>> a.y = 6 >>> a.__dict__ {'y': 6} >>> a.x 5 -- nosy: +rhettinger

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Antoine Pitrou
Antoine Pitrou added the comment: You can have both a dict and slots by subclassing: >>> class A: ...: __slots__ = ('x',) ...:

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
Change by Pierre Glaser : Added file: https://bugs.python.org/file48113/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
Change by Pierre Glaser : Removed file: https://bugs.python.org/file48112/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
Change by Pierre Glaser : Removed file: https://bugs.python.org/file48111/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
Change by Pierre Glaser : Added file: https://bugs.python.org/file48112/test_slots.py ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
Pierre Glaser added the comment: It turns out that both pickle and _pickle implement this feature, but the behavior is inconsistent. - As a reminder, instances of slotted classes do not have a dict attribute (1) - On the other side, when pickling slotted class instances, __getstate__ can

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Antoine Pitrou
Antoine Pitrou added the comment: Does it still work? With both the C and Python pickler? Can you post an example? -- ___ Python tracker ___

[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)

2019-02-07 Thread Pierre Glaser
New submission from Pierre Glaser : Hello all, This 16-year old commit (*) allows an object's state to be updated using its slots instead of its __dict__ at unpickling time. To use this functionality, the state keyword-argument of Pickler.save_reduce (which maps to the third item of the tuple