Hypothesis: Iterable strategy gives elements of wrong types

Created on 22 Oct 2020  路  2Comments  路  Source: HypothesisWorks/hypothesis

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,),
)
bug

All 2 comments

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zac-HD picture Zac-HD  路  7Comments

Zac-HD picture Zac-HD  路  4Comments

pckroon picture pckroon  路  4Comments

sobolevn picture sobolevn  路  8Comments

rlgomes picture rlgomes  路  3Comments