Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48729

Re: decorator to fetch arguments from global objects

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'none:': 0.07; '__init__': 0.09; 'exist,': 0.09; 'methods,': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; 'at.': 0.16; 'attribute,': 0.16; 'none.': 0.16; 'once.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'repeatedly.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'written,': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'decorators': 0.24; 'instance,': 0.24; 'posts': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; 'specified': 0.30; 'context.': 0.31; 'writes:': 0.31; 'class': 0.32; 'another': 0.32; 'checking': 0.33; 'subject:from': 0.34; 'common': 0.35; 'something': 0.35; 'really': 0.36; 'should': 0.36; 'too': 0.37; 'clear': 0.37; 'easily': 0.37; 'represent': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'central': 0.64; 'andrea': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: decorator to fetch arguments from global objects
Date Wed, 19 Jun 2013 12:44:42 -0400
References <CAF_E5JYg39VdwmLFnyXNOMPRx1UD8ZNGiBRpqgU=A_9rU_ukpw@mail.gmail.com> <kppv2q$shk$1@ger.gmane.org> <CAF_E5JZ3afve8WxOS_vmL_i9vC863uVYc723fV4NPAS=xod7vQ@mail.gmail.com> <loom.20130619T090208-281@post.gmane.org> <loom.20130619T095541-456@post.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
In-Reply-To <loom.20130619T095541-456@post.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3588.1371660313.3114.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371660313 news.xs4all.nl 15919 [2001:888:2000:d::a6]:47984
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48729

Show key headers only | View raw


On 6/19/2013 4:03 AM, Wolfgang Maier wrote:
> Wolfgang Maier <wolfgang.maier <at> biologie.uni-freiburg.de> writes:
>
>>
>> andrea crotti <andrea.crotti.0 <at> gmail.com> writes:
>>
>>> 2013/6/18 Terry Reedy <tjreedy <at> udel.edu>
>>>
>>> Decorators are only worthwhile if used repeatedly. What you specified can
>> easily be written, for instance, as
>>> def save_doc(db=None):
>>>    if db is None:
>>>      db = fetch_from_global()
>>>    if isinstance(db, dbclass):
>>>      save_it()
>>>    else:
>>>      raise ValueError('need dbobject')
>
> Another suggestion, without knowing too much about your code's architecture:
> why not *initialize* your Entity instance with a db_out attribute, so you do
> Terry's db checking only in one central place - Entity's __init__ method?

Your pair of posts pretty much say what I was trying to get at. If 
Entity does not prepresent anything, it should not exist, and the 
'methods' should be functions with boilerplate factored out. If entity 
does represent anything, it should be the parameter common to all 
methods, the db. I had not really cognized before that an advantage of 
defining a class is to setup and validate the central object just once.

It is still not clear to me why db should ever by bound to None. That 
must have something to do with the undisclosed context.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: decorator to fetch arguments from global objects Terry Reedy <tjreedy@udel.edu> - 2013-06-19 12:44 -0400

csiph-web