Sometimes the number of kwargs of a method increase to a level where I think it should be refactored.
Example:
def foo(important=False, debug=False, dry_run=False, ...):
....
sub_foo(important=imporant, debug=debug, dry_run=dry_run, ...)
My current preferred solution:
class Args(object):
...
def foo(args):
sub_foo(args)
First question: How to call Args
? Is there a well known description or design pattern?
Second question: Does Python have something which I could use as base class for Args
?
Update
I use Python work daily since 13 years. I used methods with many kwargs and wrote methods with many kwargs. During the last weeks a read the book "clean code" and I liked it. Somehow it is like wearing an other pair of glasses now. My old code works, but it is not nice to look at. Splitting long methods into several smaller methods is easy. But I am not sure how to handle methods with kwargs-bloat.