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


Groups > comp.lang.python > #6772 > unrolled thread

Re: scope of function parameters (take two)

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2011-05-31 19:14 -0600
Last post2011-05-31 19:14 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#6772 — Re: scope of function parameters (take two)

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-31 19:14 -0600
SubjectRe: scope of function parameters (take two)
Message-ID<mailman.2348.1306890897.9059.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web