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


Groups > comp.lang.python > #6737

Re: scope of function parameters (take two)

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
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; 'subject:two': 0.07; 'wrapper': 0.07; 'be:': 0.09; 'subject:parameters': 0.09; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; '*args,': 0.16; 'arg': 0.16; 'nargs': 0.16; 'subject:function': 0.16; '\xa0for': 0.16; 'argument': 0.16; 'tue,': 0.17; 'keyword': 0.19; 'cheers,': 0.19; 'work,': 0.20; 'header:In-Reply-To:1': 0.21; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'library.': 0.25; 'function': 0.25; 'received:209.85.161': 0.26; 'message-id:@mail.gmail.com': 0.28; 'version': 0.29; 'module': 0.30; 'args)': 0.30; 'email name:': 0.30; 'named': 0.32; 'skip:\xa0 30': 0.32; 'to:addr:python-list': 0.33; 'break': 0.33; 'skip:" 20': 0.33; 'daniel': 0.34; 'there': 0.35; '8bit%:3': 0.35; 'module.': 0.35; 'usual': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'third- party': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'subject: (': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; '31,': 0.65
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=NsrWcq/TCWGoUGPyHXi5IANMFfjNL2hP9C5V0WmD88w=; b=mTvTGCRuQyruUiOYV/VlvychT09WhTe99OEjuSIFNMTfFVYSG3LrdWLAtVIevMNdmk zJKDBXpfDyFpusjE7kx2c55tIMM+9lUC8oSgU1xO/yqqWnGLqyE8Gpwdz6UXZkfwmWaO HcLUv3uT76YpyP6l9Ls6XBqST742WlBk5e21U=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=U2WekW4RTkdw6iAcHcSH807mlHQHd58m4xewBfA58qVeB8tgheWyPIgiEE3Jcghv6G PWGlfcO9bYlHPl+JwrArAAVOCFQAYpmdermePzWQe2X/SwdXDz5W5C3ZF0u2lDiLEFV/ sZfeu8jCOsRklOQ1YV5+vFYbL7uesMtMMLnw8=
MIME-Version 1.0
In-Reply-To <BANLkTikH0S4TNAjZzfAj6mAQoTeXLYFpgQ@mail.gmail.com>
References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <F4EAD1ED-563D-4D6E-A50C-68308A9F26B7@mcgill.ca> <BANLkTin5exEpDkE3on3BAaWwHOjpg_vC8g@mail.gmail.com> <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> <BANLkTikH0S4TNAjZzfAj6mAQoTeXLYFpgQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 31 May 2011 10:16:12 -0600
Subject Re: scope of function parameters (take two)
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.2319.1306858604.9059.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 82.94.164.166
X-Trace 1306858604 news.xs4all.nl 49178 [::ffff:82.94.164.166]:54310
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6737

Show key headers only | View raw


On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev <dan.kluev@gmail.com> wrote:
> @decorator.decorator
> def copy_args(f, *args, **kw):
>    nargs = []
>    for arg in args:
>        nargs.append(copy.deepcopy(arg))
>    nkw = {}
>    for k,v in kw.iteritems():
>        nkw[k] = copy.deepcopy(v)
>    return f(*nargs, **nkw)

There is no "decorator" module in the standard library.  This must be
some third-party module.  The usual way to do this would be:

def copy_args(f):
    @functools.wraps(f)
    def wrapper(*args, **kw):
        nargs = map(copy.deepcopy, args)
        nkw = dict(zip(kw.keys(), map(copy.deepcopy, kw.values())))
        return f(*nargs, **nkw)
    return wrapper

Note that this will always work, whereas the "decorator.decorator"
version will break if the decorated function happens to take a keyword
argument named "f".

Cheers,
Ian

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


Thread

Re: scope of function parameters (take two) Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-31 10:16 -0600

csiph-web