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

Iterable strategy gives elements of wrong types #2645

Closed
tsx opened this issue Oct 22, 2020 · 2 comments · Fixed by #2646
Closed

Iterable strategy gives elements of wrong types #2645

tsx opened this issue Oct 22, 2020 · 2 comments · Fixed by #2646
Labels
bug something is clearly wrong here

Comments

@tsx
Copy link

tsx commented Oct 22, 2020

It appears to give me tuples of ints when asked for iterables of instances of my own class. Generating individual instances of my own class the same way (via annotation) works perfectly.

Version: 5.37.4. Also tried current master - same issue.

Here's an example:

from typing import Iterable

from hypothesis import given, infer


class My:
    def __init__(self, a: str):
        self.a = a


@given(i=infer)
def test_iterable(i: Iterable[My]):
    assert all(isinstance(e, My) for e in i)

Fails with:

    @given(i=infer)
>   def test_iterable(i: Iterable[My]):

repro.py:12:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

i = (0,)

    @given(i=infer)
    def test_iterable(i: Iterable[My]):
>       assert all(isinstance(e, My) for e in i)
E       assert False
E        +  where False = all(<generator object test_iterable.<locals>.<genexpr> at 0x7fcb12b74510>)

repro.py:13: AssertionError
--------------------------- Hypothesis ---------------------------
Falsifying example: test_iterable(
    i=(0,),
)
@Zac-HD
Copy link
Member

Zac-HD commented Oct 22, 2020

Thanks for reporting this! Definitely a bug, fortunately with a very simply fix which should be out soon 🙂

@tsx
Copy link
Author

tsx commented Oct 22, 2020

Thank you so much! I've started working on it myself, didn't notice you're on it and posted my own PR. It's inferior to what you did so I closed it.

@Zac-HD Zac-HD added the bug something is clearly wrong here label Oct 24, 2020
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
2 participants