Closed tbm closed 9 years ago
Original comment by Gary Peck (Bitbucket: tylix, GitHub: garyp).
You could also implement AttrDict
like this to avoid having to override __getattr__
at all (though note the couple potential cons mentioned at http://stackoverflow.com/a/14620633):
class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).
I removed AttrDict. Metadata is now represented as a plain old dict. https://bitbucket.org/blais/beancount/src/1f029cd07e5c77c2b7e5e09b998471ae086131de/CHANGES?at=default&fileviewer=file-view-default#CHANGES-7 (Make sure to delete all .picklecache files if you've been using the load cache.)
Thanks again for reporting this problem.
Original report by Nathan Grigg (Bitbucket: nathangrigg, GitHub: nathangrigg).
On an
AttrDict
instance (or anything containing one, e.g. aPosting
),copy.deepcopy
fails.The reason is that deepcopy checks for a
__deepcopy__
method at each stage, and accessingAttrDict.__deepcopy__
raises aKeyError
(and deepcopy expects anAttributeError
).(The reason I'm using deepcopy is that I'm splitting a posting into two pieces, and I don't want their position or meta fields to be incorrectly linked.)
Example fix: