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.

classification
Title: Pickle protocol 2 fails on private slots.
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: dvarrazzo, georg.brandl, tim.peters, zseil
Priority: normal Keywords:

Created on 2006-03-05 04:18 by dvarrazzo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg27680 - (view) Author: Daniele Varrazzo (dvarrazzo) * Date: 2006-03-05 04:18
The pickling protocol 2 can manage new style objects
defining __slots__ and without __dict__. Anyway it
fails when one of the slots is "private".

>>> class C1(object):
	__slots__ = ["__priv"]
	def __init__(self):
		self.__priv = 42
	def get_priv(self):
		return self.__priv

>>> C1().get_priv()
42
>>> import pickle
>>> pickle.loads(pickle.dumps(C1(), 2)).get_priv()

Traceback (most recent call last):
  File "<pyshell#258>", line 1, in -toplevel-
    pickle.loads(pickle.dumps(C1(), 2)).get_priv()
  File "<pyshell#255>", line 6, in get_priv
    return self.__priv
AttributeError: _C1__priv

of course redefining __getstate__ and __setstate__
bypasses the problem.

the cPickle module shows the same issue.
msg27681 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-09 08:21
Logged In: YES 
user_id=849994

Confirmed with pickle and cPickle here.
msg27682 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2006-03-27 05:50
Logged In: YES 
user_id=1326842

The bug is in the copy_reg module.
object.__reduce_ex__ calls function 
_slotnames in that module.
There is another bug when __slots__
is a single string. Examples below.

>>> import copy_reg
>>> class A(object):
...     __slots__ = ('__spam',)
...
>>> class B(object):
...     __slots__ = 'spam'
...
>>> copy_reg._slotnames(A) # should be ['_A__spam']
['__spam']
>>> copy_reg._slotnames(B) # should be ['spam']
['s', 'p', 'a', 'm']
msg27683 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-31 18:27
Logged In: YES 
user_id=849994

Fixed with commit of patch #1462313.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42981
2006-03-05 04:18:31dvarrazzocreate