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

Feature Request: make builds() understand __wrapped__ functions #2495

Closed
pschanely opened this issue Jul 18, 2020 · 2 comments · Fixed by #3095
Closed

Feature Request: make builds() understand __wrapped__ functions #2495

pschanely opened this issue Jul 18, 2020 · 2 comments · Fixed by #3095
Labels
enhancement it's not broken, but we want it to be better

Comments

@pschanely
Copy link
Contributor

pschanely commented Jul 18, 2020

Per the docs, the hypothesis builds function uses python's getfullargspec to determine parameters. Sadly, this means that some traditional ways of wrapping functions will hide the real parameters.

An example:

from hypothesis import given, infer
from functools import wraps

def logged(f):
    @wraps(f)
    def wrapper(*a, **kw):
        print('I was called')
        return f(*a, **kw)
    return wrapper

class Foo:
    @logged
    def __init__(self, i: int):
	    pass

@given(foo = infer)
def test_foo_test(foo: Foo):
    assert True

test_foo_test()

This yields the follow error:

TypeError: __init__() missing 1 required positional argument: 'i'

I suspect that using inspect's signature function would help here, but that might be a pretty invasive change?

@Zac-HD Zac-HD added the enhancement it's not broken, but we want it to be better label Jul 19, 2020
@Zac-HD
Copy link
Member

Zac-HD commented Jul 19, 2020

IMO this is clearly justified; cases where signature's default follow_wrapped=True is counterproductive do exist but are very rare.

#2218 even has "consider replacing uses of inspect.getfullargspec with inspect.signature" as one of the remaining checklist items - and while I didn't get around to that as part of our more general dropping-python-2 code modernisation, it shouldn't be that big a deal to do so now.

@Zac-HD
Copy link
Member

Zac-HD commented Jul 20, 2020

Aaaaand, it breaks a lot of subtle things: master...Zac-HD:signature-upgrade

There might be something small and crucial that I missed, but 🤷‍♂️ I'm leaving it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants