"Schmitt Uwe (ID SIS)" <uwe.schmitt at id.ethz.ch> writes: > I discovered a problem using cPickle.loads from CPython 2.7.6. > > The last line in the following code raises an infinite recursion > > class T(object): > > def __init__(self): > self.item = list() > > def __getattr__(self, name): > return getattr(self.item, name) > > import cPickle > > t = T() > > l = cPickle.dumps(t) > cPickle.loads(l) ... > Is this a bug or did I miss something ? The issue is that your __getattr__ raises RuntimeError (due to infinite recursion) for non-existing attributes instead of AttributeError. To fix it, you could use object.__getattribute__: class C: def __init__(self): self.item = [] def __getattr__(self, name): return getattr(object.__getattribute__(self, 'item'), name) There were issues in the past due to {get,has}attr silencing non-AttributeError exceptions; therefore it is good that pickle breaks when it gets RuntimeError instead of AttributeError. -- Akira
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4