Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for signature copying #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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