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


Groups > comp.lang.python > #6772

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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'wed,': 0.03; 'library,': 0.05; 'pylons,': 0.07; 'subject:two': 0.07; 'variant': 0.07; 'python': 0.08; 'url:pypi': 0.08; 'ah,': 0.09; 'assumed': 0.09; 'be:': 0.09; 'decorator': 0.09; 'kelly': 0.09; 'relies': 0.09; 'subject:parameters': 0.09; 'though:': 0.09; 'pm,': 0.10; '>>>': 0.12; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'example).': 0.16; 'see.': 0.16; 'subject:function': 0.16; 'test()': 0.16; '\xa0this': 0.16; 'argument': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr:python-list': 0.17; 'tue,': 0.17; 'keyword': 0.19; 'simpler': 0.19; 'cheers,': 0.19; 'work,': 0.20; 'header:In-Reply- To:1': 0.21; 'cc:2**0': 0.22; 'breaks': 0.23; 'last):': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'code': 0.24; "doesn't": 0.25; 'library.': 0.25; 'function': 0.25; 'not.': 0.26; 'received:209.85.161': 0.26; 'work.': 0.28; 'correct': 0.28; 'message-id:@mail.gmail.com': 0.28; 'version': 0.29; 'cc:addr:python.org': 0.30; 'module': 0.30; 'decorators': 0.30; 'signatures': 0.30; 'typeerror:': 0.30; 'named': 0.32; 'break': 0.33; 'skip:" 20': 0.33; 'file': 0.34; 'daniel': 0.34; 'there': 0.35; '"",': 0.35; 'module.': 0.35; 'usual': 0.35; 'test': 0.35; 'problems': 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; 'your': 0.60; '31,': 0.65; 'here': 0.66; '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:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=VF6JTAjQNapCoMWkTxEaOp4fe5CZzdFp5no19N0XF9I=; b=gt0bNC5AXG17MN4NY9x1bPv4M2PiAjQl4IlJQSjoiwarYxkaOrh51RMqsOJ8ud6/UR qn5vHDfsLiho8X21Jm3l2+R1CmjuxWMWjc25YIFkHD7sNCFwTL+5nhoXpJGsGhPhDS8p HL+JTlMcW8LQdyq2+cLkJ+e/UDIAn3Y+Zb5oA=
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 :cc:content-type:content-transfer-encoding; b=iQBSi8J9rJla8vvye1DN7d/EAwd1k6nX9BZG4Qve5JAhTX8vxwPvpqE1ozWI68w393 7us1UEyIoNK5UUoD/DNUnZwHZzMd0ywjUfY1oCSFCzahNZ5TC6+rgR+HZ56Q4/9PoO/Q jD1XnibKi3dEtsh9HjYcOsQiOiPD9QGEa41BE=
MIME-Version 1.0
In-Reply-To <BANLkTinpPDgdYfEqRQSeoMkyEvzgmJOQdA@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> <BANLkTinpPDgdYfEqRQSeoMkyEvzgmJOQdA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 31 May 2011 19:14:26 -0600
Subject Re: scope of function parameters (take two)
To Daniel Kluev <dan.kluev@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc Python <python-list@python.org>
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.2348.1306890897.9059.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 82.94.164.166
X-Trace 1306890897 news.xs4all.nl 49183 [::ffff:82.94.164.166]:46423
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6772

Show key headers only | View raw


On Tue, May 31, 2011 at 6:04 PM, Daniel Kluev <dan.kluev@gmail.com> wrote:
> 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).

Ah, I see.  I assumed it was much simpler than it is.  I found a way
to break it with Python 3, though:

>>> @copy_args
... def test(*, f):
...     return f
...
>>> test(f=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 2, in test
  File "<stdin>", line 6, in copy_args
TypeError: test() needs keyword-only argument f

The interesting thing here is that the decorated function has exactly
the correct function signature; it just doesn't work.

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 19:14 -0600

csiph-web