Avoid initializing kwargs in signature as they might not work as expected when you need to pass kwargs from other methods

$ cat test_kwargs.py 
def m1(a, b=2):
    print a, b
def m2(a, b=None):
    ​m1(a, b=b)
m1(1)
m2(1)
m1(1, 2)
m2(1, 2)
$ python test_kwargs.py 
1 2
1 None
1 2
1 2
A better version of the above methods would be,
$ cat test_kwargs.py def m1(a, b=None): if b is None: b = 2 print a, b def m2(a, b=None): m1(a, b=b) m1(1) m2(1) m1(1, 2) m2(1, 2) $ python test_kwargs.py 1 2 1 2 1 2 1 2​


Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Weakref proxy is for instance only ...

To speed up accessing files on nfs shares on a ubuntu machine ...