Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6772
| References | (2 earlier) <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 | 2011-05-31 19:14 -0600 |
| Subject | Re: scope of function parameters (take two) |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2348.1306890897.9059.python-list@python.org> (permalink) |
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
Re: scope of function parameters (take two) Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-31 19:14 -0600
csiph-web