hypothesis
hypothesis copied to clipboard
`hypothesis.stateful.consumes(bundle).flatmap` gives `TypeError: BundleConsumer.__init__() got an unexpected keyword argument 'consume'`
A script for reproduction
from hypothesis import strategies as st
from hypothesis.stateful import (
Bundle,
RuleBasedStateMachine,
consumes,
initialize,
rule,
)
class Reproduction(RuleBasedStateMachine):
my_bundle = Bundle('my_bundle')
@initialize(target=my_bundle)
def set_initial(self, /) -> str:
return 'sample text'
@rule(
character=consumes(my_bundle).flatmap(
lambda value: st.sampled_from(value)
)
)
def check(self, /, *, character: str):
assert isinstance(character, str)
assert len(character) == 1
TestCase = Reproduction.TestCase
Seems to be caused by #4187: https://github.com/HypothesisWorks/hypothesis/pull/4187/files#diff-365e582b9d2775221fe30ecfb4149f79366c3f59ea1779cbbcb518e3247151ceR556-R558
The issue appears to be that the BundleConsumer.__init__ method does not accept the consume parameter of the parent Bundle class's constructor.