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 msyang
Recipients msyang
Date 2008-08-21.19:21:36
SpamBayes Score 3.4648e-06
Marked as misclassified No
Message-id <1219346500.78.0.74794831892.issue3635@psf.upfronthosting.co.za>
In-reply-to
Content
# pickle.dumps is not able to process an instance of
# a class that inherits from 'dict' and
# overrides the built-in __getattribute__ method
# but can successfully process one that 
# overrides the__getattr__ method

>>> class Examp1(dict):
...   def __getattr__(self,name):
...     return self[name]
... 
>>> class Examp2(dict):
...   def __getattribute__(self,name):
...     return self[name]
... 
>>> ex1 = Examp1()
>>> ex2 = Examp2()
>>> ex1['aKey'] = (3,4)
>>> ex2['aKey2'] = (4,5)
>>> ex1
{'aKey': (3, 4)}
>>> ex1.aKey
(3, 4)
>>> ex2
{'aKey2': (4, 5)}
>>> ex2.aKey2
(4, 5)
>>> import pickle
>>> pickle.dumps(ex1)
b'\x80\x03c__main__\nexamp1\nq\x00)\x81q\x01X\x04\x00\x00\x00aKeyq\x02K\x03K\x04\x86q\x03s}q\x04b.'
>>> pickle.dumps(ex2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[hidden]/python3/3.0b2/common/lib/python3.0/pickle.py", line
1319, in dumps
    Pickler(f, protocol).dump(obj)
  File "<stdin>", line 3, in __getattribute__
KeyError: '__reduce_ex__'
History
Date User Action Args
2008-08-21 19:21:41msyangsetrecipients: + msyang
2008-08-21 19:21:40msyangsetmessageid: <1219346500.78.0.74794831892.issue3635@psf.upfronthosting.co.za>
2008-08-21 19:21:39msyanglinkissue3635 messages
2008-08-21 19:21:36msyangcreate