Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Static caching property Date: Tue, 22 Mar 2016 03:54:32 +1100 Lines: 16 Message-ID: References: <35a5c4206a0c40e584d62d5d37b068b3@activenetwerx.com> <56f0230e$0$1616$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de EYMGk1sjtMnDtAkcraRyhgCOQ/IMh3lIV+AGRKw78CmA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'static': 0.03; 'option,': 0.07; 'api': 0.09; 'cc:addr :python-list': 0.09; '22,': 0.09; 'descriptor': 0.09; '2016': 0.16; 'deferred': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'refers': 0.18; "shouldn't": 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'class,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'sense': 0.26; 'message- id:@mail.gmail.com': 0.27; 'var': 0.27; 'callable': 0.29; "i'm": 0.30; 'non': 0.32; 'expensive': 0.32; 'class': 0.33; 'instances': 0.33; 'option.': 0.33; 'tue,': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'clear': 0.35; 'protocol': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'end': 0.39; 'means': 0.39; 'test': 0.39; 'sure': 0.39; 'some': 0.40; 'mar': 0.65; 'chrisa': 0.84; 'to:none': 0.91; 'execution,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=3BKWO+E8gi2cp6Z58yschsaINgdIf9FuSkYSoTeFkpY=; b=F7F/iZ0yH/ixmKpUeNNp0RhNo71wVKqs3YpOYm/KLeoh0AIWEvWqVZu93X2r6+bVxL vdzkjO9uToSlojnARg3Uoml5EoOjgvOmC6qFRMp45Fwlzbt0t8WiaM7p3enjC+MEg7Ht Ct/yLXizumVyvZNT5Q6uMsibDKL1U/AEEpmBtk24oSelkMlivYfl/tRUjh6oH0KbfxVw 6cNEJNYEBZE9MbR1P6MDl+CwOE6fpSVGqXYue6p24pd5NAbLnMSKq22P7Uj6ZTaH2gly Hht9/SykAuajZsaMtxMQS4cPC1Ttkhm1RHnvGYtlTjebz8nv51yv9LNT2dPpPZ/rqp+e AY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=3BKWO+E8gi2cp6Z58yschsaINgdIf9FuSkYSoTeFkpY=; b=KM56Xw9KU3Sh8ItYUOz8RDuehvZpOrKhDtTvc2EghVr/ipsv7A9xpPzHJd6qaEzHcf vYv8vj34SHrM7vvemCHVhI9PxVA/S8Qv7vmZDYDWq9tVENxc+w6yqfS3DEIGyhTcYPg0 B3f8YyNPwiOSi6g0OyFG30BvwxepP2ptbEUU9oB/bp/l7mr3q2PUQBYYsiObaB/peUX1 hU2XE1ni+xfaBWVXrIqhWWl2V/4m0OuN+ISXlbUqd+LT2X5TsnJXzW8rQLLZDqOcMbbH V0iaBlFNUouUVinK6/avlpL0Qwg4bhHvy65fAyxY87/H0pYG2979a3ffaSsJT9im2Ars WCFQ== X-Gm-Message-State: AD7BkJLe1/i2TZFWNMgVOpAIXMXPobyakPv4122d7Kmgt6GLNGZd3nCD5ASU84WQ1euVOTCLApB2ntC9+GIYbA== X-Received: by 10.107.63.139 with SMTP id m133mr27238499ioa.157.1458579272354; Mon, 21 Mar 2016 09:54:32 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105374 On Tue, Mar 22, 2016 at 3:49 AM, Joseph L. Casale wrote: > Right, but _private refers to an api call that is expensive and may not even be accessed, > so while I may new up three instances of Test across a, b and c, if none of those end up > accessing var x, it shouldn't get fetched. Without some deferred execution, if the value > of _private is a callable whose return value is what I am interested in, it gets invoked the > moment the class is compiled. > > In the non static sense this is trivial to accomplish with the descriptor protocol, I am just not > clear for the static sense. One solution is to use descriptor protocol on the class, which means using a metaclass. I'm not sure it's the best option, but it is an option. ChrisA