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

Using typing in a target function signature breaks strategies.builds #946

Closed
hoefling opened this issue Oct 18, 2017 · 4 comments
Closed
Labels
bug something is clearly wrong here

Comments

@hoefling
Copy link
Contributor

hoefling commented Oct 18, 2017

In our code, we rely a lot on typing feature that was first introduced in Python 3.5 (see PEP-484) so the breakage of typed signatures is a major issue for us.

To reproduce run the following script with latest hypothesis==3.33.0 and any of python{3.5,3.6,3.7dev}:

from typing import Tuple
from hypothesis import strategies as st

def target_untyped(num, flag):
    return (num, flag, )

def target_typed(num: int, flag: bool) -> Tuple[int, bool]:
    return (num, flag, )

StrategyUntypedPositionalArgs = st.builds(
    target_untyped,
    st.integers(),
    st.booleans(),
)

StrategyTypedPositionalArgs = st.builds(
    target_typed,
    st.integers(),
    st.booleans(),
)

# target with untyped args works
print(StrategyUntypedPositionalArgs.example())

# target with typed args raises TypeError
print(StrategyTypedPositionalArgs.example())

Bisecting shows the first failing commit is:

7f9fe4ae8aa156f54a4a66a0044763129a8d1d37 is the first bad commit
commit 7f9fe4ae8aa156f54a4a66a0044763129a8d1d37
Author: Zac-HD <zac.hatfield.dodds@gmail.com>
Date:   Sun Jul 23 20:55:59 2017 +1000

    Use from_type for missing required args to builds()

:040000 040000 89f12436a970300b9f9500ace096ff4c0bbe29bd 1369e4cef83506b9a5bf17b3b2329a1670a846d9 M	src

Workaround suggestion: do not update to 3.14.0, last working version is 3.13.0.

@Zac-HD Zac-HD added the bug something is clearly wrong here label Oct 18, 2017
@Zac-HD
Copy link
Member

Zac-HD commented Oct 18, 2017

Thanks for reporting this - providing a reproducing case and the bisection is really useful. I'll post a fix as soon as possible 😄

@hoefling
Copy link
Contributor Author

Glad if this helps; if you need any additional info, don't hesitate to ask.

@Zac-HD
Copy link
Member

Zac-HD commented Oct 18, 2017

I've already tracked it down - there's a one-line fix to the introspection where I called it with the tuple of received arguments but handled a tuple of argument names. Just writing a regression test now, then changelog and it'll be released as soon as someone can review it.

@hoefling
Copy link
Contributor Author

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

No branches or pull requests

2 participants