[issue26579] Support pickling slots in subclasses of common classes

2022-04-07 Thread STINNER Victor


STINNER Victor  added the comment:

> bpo-26579: Add object.__getstate__(). (GH-2821)
> https://github.com/python/cpython/commit/884eba3c76916889fd6bff3b37b8552bfb4f9566

This change introduced reference leaks: see bpo-47250.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2022-04-06 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.11 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2022-04-06 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 884eba3c76916889fd6bff3b37b8552bfb4f9566 by Serhiy Storchaka in 
branch 'main':
bpo-26579: Add object.__getstate__(). (GH-2821)
https://github.com/python/cpython/commit/884eba3c76916889fd6bff3b37b8552bfb4f9566


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2017-11-15 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests:  -4360

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2017-11-15 Thread Yury Selivanov

Change by Yury Selivanov :


--
pull_requests: +4360

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2017-07-23 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +haypo, r.david.murray
versions: +Python 3.7 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2017-07-23 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +2873

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2016-07-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

An alternative way is to expose a default state as object.__getstate__(). It is 
more efficient since it is implemented in C. Following patch implements this 
approach.

--
Added file: http://bugs.python.org/file43716/object_getstate.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2016-06-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Synchronized with current sources.

--
Added file: http://bugs.python.org/file43462/copyreg_getstate2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2016-03-19 Thread Berker Peksag

Changes by Berker Peksag :


--
nosy: +berker.peksag

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26579] Support pickling slots in subclasses of common classes

2016-03-19 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Pickling and copying instances of subclasses of some basic classes pickles and 
copies instance attributes. Example:

>>> class BA(bytearray):
... pass
... 
>>> b = BA(b'abc')
>>> b.x = 10
>>> c = copy.copy(b)
>>> c.x
10
>>> c = pickle.loads(pickle.dumps(b))
>>> c.x
10

But this doesn't work if attributes are saved not in instance dictionary, but 
in slots.

>>> class BA(bytearray):
... __slots__ = ('x',)
... 
>>> b = BA(b'abc')
>>> b.x = 10
>>> c = copy.copy(b)
>>> c.x
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: x
>>> c = pickle.loads(pickle.dumps(b))
>>> c.x
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: x

Since using __slots__ is implementation detail, this failure can be considered 
as a bug.

Proposed patch adds support of pickling and copying slots in subclasses of all 
classes that already support pickling and copying non-slot attributes. It is 
backward compatible, classes with slots can be unpickled on older Python 
versions without slots. Affected classes: bytearray, set, frozenset, 
weakref.WeakSet, collections.OrderedDict, collections.deque, datetime.tzinfo.

The patch adds the copyreg._getstate() function for Python classes and exposes 
the _PyObject_GetState() function for extension classes. An alternative (and 
simpler for end user) solution would be to add default implementation as 
object.__getstate__(). But this is not easy to reject non-pickleable classes 
(issue22995) in this case, since __getstate__ is looked up as instance 
attribute, not as other special methods.

--
components: Extension Modules, Library (Lib)
files: copyreg_getstate.patch
keywords: patch
messages: 261903
nosy: alexandre.vassalotti, pitrou, rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Support pickling slots in subclasses of common classes
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file42183/copyreg_getstate.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com