----- Original Message -----

> From: Jean-Michel Pichavant <jeanmic...@sequans.com>
> To: Albert-Jan Roskam <fo...@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" <fo...@yahoo.com>
>>  > From: Jean-Michel Pichavant <jeanmic...@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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to