Is there are good DRY fix for this painful design pattern?
Ian Kelly
ian.g.kelly at gmail.com
Mon Feb 26 16:43:22 EST 2018
On Mon, Feb 26, 2018 at 2:37 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Mon, Feb 26, 2018 at 1:09 PM, <marco.nawijn at colosso.nl> wrote:
>> def foo(self, *args, **kwargs):
>> assert len(args) == 0
>
> Better:
>
> def foo(self, **kwargs):
>
>> So, use the inspect module to detect the valid arguments
>> from the class initializer. Then use **kwargs in every
>> class method. It would be nice if the full method signature
>> can be kept, but I have not yet figured out if this is
>> possible.
>
> https://pypi.python.org/pypi/decorator/4.2.1
Also, in Python 3.4+ you can just create a Signature object (either
from scratch or by calling inspect.signature()) and then assign it to
the function's __signature__ attribute.
More information about the Python-list
mailing list