Skip to content

Conversation

@nickolasrm
Copy link

Made this modification because I had a code whose minimock couldn't help me easily:

def parse_varargs(f, *args, **kwargs):
    return inspect.signature(f).bind(*args, **kwargs).arguments

The code above represents a varargs parser I used in decorators. However, because the function f, already mocked, was passed to it, and because its signature was different, then parse_varargs output did not work as expected.

>>> def parse_varargs(f, *args, **kwargs):
...     return inspect.signature(f).bind(*args, **kwargs).arguments

>>> def foo(a, b, c=4):
...     pass

>>> mock('foo', copy_signature=True)
>>> parse_varargs(foo, 3, 4, c=5)
{'a': 3, 'b': 4, 'c': 5}
>>> restore()

>>> mock('foo')
>>> parse_varargs(foo, 3, 4, c=5)
Traceback (most recent call last):
  ...
TypeError: unexpected object <Mock 0x1f91fb498e0 foo.__signature__> in __signature__ attribute
>>> restore()

I hope this pr can improve this wonderful lib that helped me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant