Skip to content

Commit be289ab

Browse files
committed
validation for provider_kw
1 parent e140bd3 commit be289ab

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,12 @@ def __init__(
16141614
observer = DataObserver()
16151615
if provider_kw is None:
16161616
provider_kw = {}
1617+
elif not isinstance(provider, type):
1618+
raise InvalidArgument(
1619+
f"Expected {provider=} to be a class since {provider_kw=} was "
1620+
"passed, but got an instance instead."
1621+
)
1622+
16171623
assert isinstance(observer, DataObserver)
16181624
self._bytes_drawn = 0
16191625
self.observer = observer

hypothesis-python/tests/conjecture/test_alt_backend.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,14 @@ def test_function(x):
595595
with pytest.raises(AssertionError) as ctx:
596596
test_function()
597597
assert (msg in ctx.value.__notes__) == (provider is UnsoundVerifierProvider)
598+
599+
600+
def test_invalid_provider_kw():
601+
with pytest.raises(InvalidArgument, match="got an instance instead"):
602+
ConjectureData(
603+
max_length=0,
604+
prefix=b"",
605+
random=None,
606+
provider=TrivialProvider(None),
607+
provider_kw={"one": "two"},
608+
)

0 commit comments

Comments
 (0)