Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83841
| Date | 2015-01-15 21:07 +0000 |
|---|---|
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| References | <41960019.9418586.1421167045799.JavaMail.root@sequans.com> |
| Subject | Re: class-based class decorator |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17773.1421356398.18130.python-list@python.org> (permalink) |
----- Original Message ----- > From: Jean-Michel Pichavant <jeanmichel@sequans.com> > To: Albert-Jan Roskam <fomcl@yahoo.com> > Cc: Python <python-list@python.org> > Sent: Tuesday, January 13, 2015 5:37 PM > Subject: Re: class-based class decorator > > ----- Original Message ----- >> From: "Albert-Jan Roskam" <fomcl@yahoo.com> >> > From: Jean-Michel Pichavant <jeanmichel@sequans.com> >> > I don't really understand how you successfuly manage positional >> > parameters, >> > since the caller may not name them. >> > I'm asking because if your intend to check only the keyword >> > parameters, >> > there's a much simplier solution. >> > >> > JM >> >> >> Hi, >> >> Can you give an example of where/how my code would fail? I do not >> intend to use *args and **kwargs, if that is what you mean. I am >> interested in hearing a simpler approach, especially if it would >> also solve the messed-up-signature problem that I mentioned. >> >> Thank you! >> >> Albert-Jan >> > > In the example you've given you've deprecated only keyword arguments. So > I was wondering... > > would the following *untested* code work ? : > > def check_deprecated_args(deprecated): > def decorator(func): > def inner(*args, **kwargs): > for p in deprecated: > if p in kwargs: > print '%s is deprecated' % p > return func(*args, **kwargs) > return inner > return decorator > This is indeed a lot simpler than a class-based version, merci bien! And now I can also make it work with the signature-preserving decorator package. Meanwhile I also found a Python 2 backport for inspect.signature, so positional args can also be used. Thanks again! Albert-Jan
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: class-based class decorator Albert-Jan Roskam <fomcl@yahoo.com> - 2015-01-15 21:07 +0000
csiph-web