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
I'm currently testing some code that deals with a recursive tree structure. Since the code already has type definitions, I was hoping to reuse them in Hypothesis by way of from_type. While I was successful in finding a way forward, some of the failed attempts seemed to uncover errors within Hypothesis.
The version that doesn't work spits out a rather long traceback:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "...\hypothesis\strategies\_internal\strategies.py", line 314, in example
example_generating_inner_function()
File "...\hypothesis\strategies\_internal\strategies.py", line 302, in example_generating_inner_function
@settings(
File "...\hypothesis\core.py", line 1023, in wrapped_test
processed_args = process_arguments_to_given(
File "...\hypothesis\core.py", line 441, in process_arguments_to_given
search_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\collections.py", line 39, in do_validate
s.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 638, in do_validate
self.mapped_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\lazy.py", line 118, in do_validate
w.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 638, in do_validate
self.mapped_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\collections.py", line 39, in do_validate
s.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 595, in do_validate
for e in self.element_strategies:
File "...\hypothesis\strategies\_internal\strategies.py", line 570, in element_strategies
if not arg.is_empty:
File "...\hypothesis\strategies\_internal\strategies.py", line 125, in accept
recur(self)
File "...\hypothesis\strategies\_internal\strategies.py", line 121, in recur
mapping[strat] = getattr(strat, calculation)(recur)
File "...\hypothesis\strategies\_internal\lazy.py", line 86, in calc_is_empty
return recur(self.wrapped_strategy)
File "...\hypothesis\strategies\_internal\strategies.py", line 121, in recur
mapping[strat] = getattr(strat, calculation)(recur)
File "...\hypothesis\strategies\_internal\deferred.py", line 80, in calc_is_empty
return recur(self.wrapped_strategy)
File "...\hypothesis\strategies\_internal\deferred.py", line 55, in wrapped_strategy
del self.__definition
AttributeError: _DeferredStrategy__definition
The text was updated successfully, but these errors were encountered:
Thanks for reporting this! To be honest it's probably cleaner to register explicit st.recursive() strategies for each type, but I can see why you'd want to use st.from_type() - and I consider this a bug to be fixed either way 🙂
I also need to appreciate this symphony of lazy evaluation for a minute:
A=Dict[str, "B"] # "B" is a forward reference, to avoid NameError. Standard.B=Union[List[str], A] # Mypy doesn't support direct recursion, but mutual is fine! 🤔# We're not actually using the "register a function" feature of inspecting the# type instance... just using the function closure to *defer harder* because# st.deferred() itself isn't enough inside the optionally-lazy st.from_type() 😕st.register_type_strategy(ForwardRef("B"), lambda_: st.deferred(lambda: bs))
# st.from_type(B) would fail herebs=st.from_type(B) # works# st.from_type(B) works here because bs is now in scope 🤯
I'm currently testing some code that deals with a recursive tree structure. Since the code already has type definitions, I was hoping to reuse them in Hypothesis by way of
from_type. While I was successful in finding a way forward, some of the failed attempts seemed to uncover errors within Hypothesis.The version that doesn't work spits out a rather long traceback:
The text was updated successfully, but these errors were encountered: