Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'append': 0.07; 'attributes': 0.07; "object's": 0.09; 'subclass': 0.09; 'such.': 0.09; 'modification': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'using,': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'thu,': 0.17; 'references': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'opposed': 0.27; 'message-id:@mail.gmail.com': 0.27; 'comparison': 0.29; 'could': 0.32; 'retain': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'ben': 0.35; "won't": 0.35; 'something': 0.35; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'believe': 0.69; 'consequences': 0.71; 'goal': 0.74; '2013': 0.84; 'effectively,': 0.84; 'snapshot': 0.84; 'subject:its': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=xueD2NISJXQtv6eBxtSUqSpae0h4GD3Ra3ZRri3rmNc=; b=ylxPJcx/LXiCfCROQqCdwtKMWj7j3KXLdOuM+QmHMDAk1b/zuYSjAMGmIlR8as2dBI gDwcdWkLd5ujVkTKzOl29Writu8siQ6M1Lp2e6QcOfv+6Kt6pEYBQqmTPyDfrDeR6x8Q 6UQfEvm7rpVikIo2+zURd3Y47jK6m5BQz8wc/KNEiD+8B5Wz3LtcCPknNSMiT5jUSjWf T58RXZjXJq0yGKIYcTuN49M3KdfjI8ao8ql/7p/yW7kFnXLI9QKQ+EbXRXVllaaY54eO fAuAHoANZhjZiA/wWcANVG0xJ/mr6QGUM8Jan6koxeiHgdQy5I+OezoZGanyR9j7XLnX AaHg== MIME-Version: 1.0 X-Received: by 10.52.88.197 with SMTP id bi5mr10017329vdb.58.1362586976928; Wed, 06 Mar 2013 08:22:56 -0800 (PST) In-Reply-To: References: Date: Thu, 7 Mar 2013 03:22:56 +1100 Subject: Re: Creating an object that can track when its attributes are modified From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362586985 news.xs4all.nl 6969 [2001:888:2000:d::a6]:40417 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40643 On Thu, Mar 7, 2013 at 3:07 AM, Ben Sizer wrote: > I also believe that this won't catch modification to existing attributes as opposed to assignments: eg. if one of the attributes is a list and I append to it, this system won't notice. Is that something I can rectify easily? The only way you could detect mutation of one of its attributes is with that object's assistance. Effectively, you would need to have a subclass of list/dict/tuple/whatever that can respond to the change. Alternatively, you could retain a deep copy and do a comparison at time of rollback; this, however, would have annoying consequences wrt performance and other references and such. What's the goal of this class? Can you achieve the same thing by using, perhaps, a before-and-after snapshot of a JSON-encoded form of the object? ChrisA