Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83491 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2015-01-09 23:30 -0700 |
| Last post | 2015-01-09 23:30 -0700 |
| 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.
Re: class-based class decorator Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-09 23:30 -0700
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-01-09 23:30 -0700 |
| Subject | Re: class-based class decorator |
| Message-ID | <mailman.17553.1420871452.18130.python-list@python.org> |
On Fri, Jan 9, 2015 at 2:26 PM, Albert-Jan Roskam <fomcl@yahoo.com.dmarc.invalid> wrote: > > > Hi, > > I am trying to write a class decorator that checks whether deprecated parameters with non-default > > arguments are used. More complete code is here: http://pastebin.com/ZqnMis6M. In the code below, > > how should I modify __call__ such that f.bar(old="oh no") prints "hello world"? > I thought it would be a fun way to play with the inspect module, but my head is numb now and I am thirsty for a beer! You can use inspect.getargspec to look up the default argument values for the target function. You can use inspect.getcallargs to map your *args and **kwargs to a dictionary of argument names and values. Since the target function will be the unbound __init__ method, you'll also want to pass in a dummy value like None for the self argument. Then you just look up each of the deprecated names in the result and flag any where the value doesn't match the default. If you were using Python 3.3+, then I would recommend using inspect.signature instead, which is a lot more powerful. But your code appears to be Python 2, so we work with what we've got.
Back to top | Article view | comp.lang.python
csiph-web