Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3164 from Zac-HD/defer-builds-inference
Register `builds()` of recursive types with constraints
- Loading branch information
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
RELEASE_TYPE: minor | ||
|
||
This release teaches :func:`~hypothesis.strategies.builds` to use | ||
:func:`~hypothesis.strategies.deferred` when resolving unrecognised type hints, | ||
so that you can conveniently register strategies for recursive types | ||
with constraints on some arguments (:issue:`3026`): | ||
|
||
.. code-block:: python | ||
class RecursiveClass: | ||
def __init__(self, value: int, next_node: typing.Optional["SomeClass"]): | ||
assert value > 0 | ||
self.value = value | ||
self.next_node = next_node | ||
st.register_type_strategy( | ||
RecursiveClass, st.builds(RecursiveClass, value=st.integers(min_value=1)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters