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


Groups > comp.lang.python > #6767

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!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <dan.kluev@gmail.com>
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; 'wed,': 0.03; 'library,': 0.05; 'args': 0.07; 'exec': 0.07; 'function,': 0.07; 'pylons,': 0.07; 'subject:two': 0.07; 'variant': 0.07; 'url:pypi': 0.08; 'be:': 0.09; 'decorator': 0.09; 'kelly': 0.09; 'relies': 0.09; 'subject:parameters': 0.09; '>>>': 0.12; 'def': 0.12; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'example).': 0.16; 'subject:function': 0.16; '\xa0this': 0.16; 'argument': 0.16; 'keyword': 0.19; 'work,': 0.20; 'header:In-Reply-To:1': 0.21; 'breaks': 0.23; 'code': 0.24; 'library.': 0.25; 'function': 0.25; 'not.': 0.26; 'pass': 0.27; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'version': 0.29; 'module': 0.30; 'decorators': 0.30; 'signatures': 0.30; 'print': 0.31; 'named': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'break': 0.33; 'skip:" 20': 0.33; 'daniel': 0.34; 'there': 0.35; 'module.': 0.35; 'usual': 0.35; 'problems': 0.36; 'uses': 0.36; 'received:google.com': 0.37; 'useful': 0.37; 'received:209.85': 0.37; 'third-party': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'subject: (': 0.39; 'skip:s 20': 0.39; 'received:209': 0.39; 'itself.': 0.39; 'to:addr:python.org': 0.39; 'best': 0.60; 'your': 0.60; 'matter': 0.63; 'url:3': 0.67
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=V37+FWu2uonOB3G50IJv2dLmj5T38hbEbTH6vAWSJfY=; b=N0gIDoBk8qfDI8hHohQtnYAjYpaeeuQgqOLIoEtPkbxL9bT7SkOmpdno29rvmUsorD 9z3gAKDdo4JoDE1InCcenueBk5IPFJaDZS4evN9toZfs1zZnzcZP7eIpc89Vf17QXrNY rehkpRuChxTs6kqG6fRMaRo2RWdG9z7dZwlQs=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=iiy+0Fu6VEcWKKY5U6z/G+0+AM/nyseLFsCcJxZ+bTSSm/L4wJYUO/S0JWWmI2+Cno wFvfJ/mR4Gj1n/r/O/fZf+UnBcBAdT2u6xQYwfH0RDecZQ2FgN6QFHRATGBuaKc5O0f2 OYSZHgkAHrZbd+iQZ2wkiH8ST9JLwScD3v9ZE=
MIME-Version 1.0
In-Reply-To <BANLkTikVniZv-wP2pQhVs7BrsBeesFudgQ@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> <BANLkTikVniZv-wP2pQhVs7BrsBeesFudgQ@mail.gmail.com>
Date Wed, 1 Jun 2011 11:04:10 +1100
Subject Re: scope of function parameters (take two)
From Daniel Kluev <dan.kluev@gmail.com>
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.2344.1306886653.9059.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 82.94.164.166
X-Trace 1306886653 news.xs4all.nl 49177 [::ffff:82.94.164.166]:57935
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6767

Show key headers only | View raw


On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>
> There is no "decorator" module in the standard library.  This must be
> some third-party module.  The usual way to do this would be:

Yes, but its very useful for decorators and provides some
not-readily-available functionality.
http://pypi.python.org/pypi/decorator/3.3.1

> 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".

No, it will not. Its the magic of decorator library, it is
signature-preserving, while your variant breaks function signature and
causes problems to any code that relies on signatures (happens with
Pylons, for example).

>>> @copy_args
... def test(a, f=None):
...     print f
...
>>> test([], f=123)
123

Basically decorator.decorator uses exec to create new function, with
signature of function you pass to your decorator, so it does not
matter what names you used for args in decorator itself.

-- 
With best regards,
Daniel Kluev

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


Thread

Re: scope of function parameters (take two) Daniel Kluev <dan.kluev@gmail.com> - 2011-06-01 11:04 +1100

csiph-web