Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: dieter Newsgroups: comp.lang.python Subject: Re: make an object read only Date: Wed, 03 Aug 2016 09:57:42 +0200 Lines: 16 Message-ID: References: <87mvku9te1.fsf@handshake.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.uni-berlin.de iRR0UsjHvGvjA/ThspRjhw13phIf8+LCRVNOnfcSnTLg== Cancel-Lock: sha1:MLJ0uIzn7eu9XAxxrUF0alYjnI0= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'reject': 0.05; 'used.': 0.05; 'canvas': 0.07; 'assigning': 0.09; 'immutable': 0.09; "object's": 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'attributes,': 0.16; 'called,': 0.16; 'dictionaries': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'repeatedly,': 0.16; 'subject:make': 0.16; 'subject:object': 0.16; '(by': 0.22; 'mixed': 0.22; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'skip:" 20': 0.26; 'methods.': 0.29; 'objects': 0.29; 'implement': 0.32; 'says': 0.32; 'changing': 0.34; 'lists': 0.34; 'could': 0.35; 'instance': 0.35; 'quite': 0.35; 'level': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'there,': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'doing': 0.38; 'wrong': 0.38; 'to:addr:python.org': 0.40; 'save': 0.60; 'your': 0.60; 'our': 0.64; 'results': 0.66; 'becker': 0.84; 'elementary': 0.84; 'subject:read': 0.84 X-Injected-Via-Gmane: http://gmane.org/ User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <87mvku9te1.fsf@handshake.de> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:112264 Robin Becker writes: > A reportlab user found he was doing the wrong thing by calling canvas.save > repeatedly, our documentation says you should not use Canvas objects after the > save method has been used. The user had mixed results :( > > It would be better to make the canvas object completely immutable all the way > down when save has been called, but I think that's quite hard as these objects > have quite a large and varied set of attributes, lists other objects > dictionaries etc etc. If changing things happen at an elementary level (by assigning to the object's instance attributes), then you could implement your on "__setattr__/__delattr__" methods. There, you could check whether you are ready to allow the change or reject it.