class-based class decorator

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Jan 13 11:37:25 EST 2015


----- Original Message -----
> From: "Albert-Jan Roskam" <fomcl at yahoo.com>
> > From: Jean-Michel Pichavant <jeanmichel at 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

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list