"Schmitt Uwe (ID SIS)" <uwe.schm...@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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com