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.
Created on 2008年08月21日 19:21 by msyang, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg71671 - (view) | Author: Michael Yang (msyang) | Date: 2008年08月21日 19:21 | |
# 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__'
|
|||
| msg87942 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年05月16日 22:57 | |
Is this related to #1730480? |
|||
| msg139216 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2011年06月26日 20:45 | |
Should this be closed for the same reason #1730480 was? If not, would this effectively be a feature request and have to wait for a new version (3.3)? |
|||
| msg148905 - (view) | Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) | Date: 2011年12月06日 03:35 | |
I don't think it is a bug. The posted code completely breaks the expected behavior of __getattribute__. With a such implementation, there is nothing we can do with this object as we cannot introspect it. Use the following if you really need this kind of behaviour: class E(dict): def __getattribute__(self,name): try: return self[name] except KeyError: return dict.__getattribute__(self, name) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:38 | admin | set | github: 47885 |
| 2011年12月06日 03:35:10 | alexandre.vassalotti | set | status: open -> closed resolution: works for me messages: + msg148905 |
| 2011年06月26日 20:45:02 | terry.reedy | set | nosy:
+ alexandre.vassalotti, terry.reedy, pitrou messages: + msg139216 versions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.1 |
| 2009年05月16日 22:57:42 | ajaksu2 | set | priority: normal versions: + Python 2.6, Python 3.1, - Python 2.5, Python 3.0 nosy: + ajaksu2 messages: + msg87942 stage: test needed |
| 2009年05月16日 22:56:32 | ajaksu2 | link | issue4712 dependencies |
| 2008年08月21日 19:21:39 | msyang | create | |