You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# test.pyfromtypingimportTypedDict, Callable, NamedTuplefromhypothesisimportgivenfromhypothesis.strategiesimportcomposite, register_type_strategy, builds, from_typeclassSomeData(TypedDict):
a: strb: int@compositedefsome_data_composite(draw: Callable):
assert0# to be sure when it worksregister_type_strategy(SomeData, some_data_composite())
@given(from_type(SomeData))deftest_some_data(item):
print(item)
I'm expecting pytest test.py to fail since there is assert 0 in some_data_composite strategy.
The test passes (hypothesis==6.3.0), but if I will replace class SomeData(TypedDict) with class SomeData(NamedTuple) or class SomeData, it will fail.
This happens because the TypedDict case is the first thing that is handled in hypothesis.strategies._internal.core._from_type, much earlier, than _global_type_lookup check.
This seems a problem for me since I'm using Hypothesis with Deal and I want to set up a default strategy for my typed dictionaries.
If this bug is confirmed, I'll try to fix it.
The text was updated successfully, but these errors were encountered:
Yep, that's a bug! We'll be happy to accept a PR to make this less hard-coded 😊
we'll also want to handle inheritance for TypedDicts - if resolving class SomeMoreData(SomeData):, the fields from SomeData should use whatever was registered for that type. It's OK to leave this for a future PR, of course - we're usually happy to take incremental improvements!
Here is a reproducible example of the problem:
I'm expecting
pytest test.pyto fail since there isassert 0insome_data_compositestrategy.The test passes (hypothesis==6.3.0), but if I will replace
class SomeData(TypedDict)withclass SomeData(NamedTuple)orclass SomeData, it will fail.This happens because the TypedDict case is the first thing that is handled in
hypothesis.strategies._internal.core._from_type, much earlier, than_global_type_lookupcheck.This seems a problem for me since I'm using Hypothesis with Deal and I want to set up a default strategy for my typed dictionaries.
If this bug is confirmed, I'll try to fix it.
The text was updated successfully, but these errors were encountered: