@@ -135,7 +135,7 @@ def event(value: str) -> None:
135
135
context .data .note_event (value )
136
136
137
137
138
- def target (observation : Union [int , float ], * , label : str = "" ) -> None :
138
+ def target (observation : Union [int , float ], * , label : str = "" ) -> Union [ int , float ] :
139
139
"""Calling this function with an ``int`` or ``float`` observation gives it feedback
140
140
with which to guide our search for inputs that will cause an error, in
141
141
addition to all the usual heuristics. Observations must always be finite.
@@ -165,11 +165,6 @@ def target(observation: Union[int, float], *, label: str = "") -> None:
165
165
and immediately obvious by around ten thousand examples
166
166
*per label* used by your test.
167
167
168
- .. note::
169
- ``hypothesis.target`` is considered experimental, and may be radically
170
- changed or even removed in a future version. If you find it useful,
171
- please let us know so we can share and build on that success!
172
-
173
168
:ref:`statistics` include the best score seen for each label,
174
169
which can help avoid `the threshold problem
175
170
<https://hypothesis.works/articles/threshold-problem/>`__ when the minimal
@@ -182,7 +177,10 @@ def target(observation: Union[int, float], *, label: str = "") -> None:
182
177
183
178
context = _current_build_context .value
184
179
if context is None :
185
- raise InvalidArgument ("Calling target() outside of a test is invalid." )
180
+ raise InvalidArgument (
181
+ "Calling target() outside of a test is invalid. "
182
+ "Consider guarding this call with `if currently_in_test_context(): ...`"
183
+ )
186
184
verbose_report (f"Saw target(observation={ observation !r} , label={ label !r} )" )
187
185
188
186
if label in context .data .target_observations :
@@ -192,3 +190,5 @@ def target(observation: Union[int, float], *, label: str = "") -> None:
192
190
)
193
191
else :
194
192
context .data .target_observations [label ] = observation
193
+
194
+ return observation
0 commit comments