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: 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: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> From: Ian Kelly Date: Tue, 31 May 2011 19:14:26 -0600 Subject: Re: scope of function parameters (take two) To: Daniel Kluev Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, May 31, 2011 at 6:04 PM, Daniel Kluev wrote: > On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: >> >> There is no "decorator" module in the standard library. =A0This must be >> some third-party module. =A0The 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=3D1) Traceback (most recent call last): File "", line 1, in File "", line 2, in test File "", 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