Kwpolska / merge_args

Merge signatures of two functions with Advanced Hackery.
BSD 3-Clause "New" or "Revised" License
30 stars 6 forks source link

Avoid taking 'default' twice for args in both signatures #3

Closed janfreyberg closed 4 years ago

janfreyberg commented 4 years ago

I noticed that the following fails (formatted as a unit test):

def test_when_kwargs_present_in_both():

    def src(a, b, c=1, d=2): ...

    @merge_args.merge_args(src)
    def dest(e, c=1, d=2): ...

    assert str(signature(dest)) == '(e, a, b, c=1, d=2)'

With this output:

$ python -m pytest -k 'test_when_kwargs_present_in_both'
>       assert str(signature(dest)) == '(e, a, b, c=1, d=2)'
E       AssertionError: assert '(e, a=1, b=2, c=1, d=2)' == '(e, a, b, c=1, d=2)'
E         - (e, a, b, c=1, d=2)
E         + (e, a=1, b=2, c=1, d=2)
E         ?      ++   ++

As you can see, at present, merge_args takes the default values for arguments c and d from both functions, but the signature actually only has each of them once

This PR fixes this while keeping all other tests passing.

janfreyberg commented 4 years ago

Thank you very much for merging this!

Would you be able to release a new version for this? I am currently adding this as a dependency in one of my libraries, and would love to have this change in there!

Kwpolska commented 4 years ago

Sure thing, I just released v0.1.4.

janfreyberg commented 4 years ago

awesome, thank you very much.