Skip to content

Commit e118dde

Browse files
committed
rename to add_observability_callback
1 parent 0b98d07 commit e118dde

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

hypothesis-python/docs/prolog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
.. |PrimitiveProvider.draw_bytes| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_bytes`
118118
.. |PrimitiveProvider.on_observation| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.on_observation`
119119
.. |PrimitiveProvider.per_test_case_context_manager| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.per_test_case_context_manager`
120-
.. |PrimitiveProvider.add_observation_callback| replace:: :data:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.add_observation_callback`
120+
.. |PrimitiveProvider.add_observability_callback| replace:: :data:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.add_observability_callback`
121121

122122
.. |AVAILABLE_PROVIDERS| replace:: :data:`~hypothesis.internal.conjecture.providers.AVAILABLE_PROVIDERS`
123123
.. |TESTCASE_CALLBACKS| replace:: :data:`~hypothesis.internal.observability.TESTCASE_CALLBACKS`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ def debug_data(self, data: Union[ConjectureData, ConjectureResult]) -> None:
833833

834834
def observe_for_provider(self) -> AbstractContextManager:
835835
def on_observation(observation: Observation) -> None:
836+
assert observation.type == "test_case"
836837
# because lifetime == "test_function"
837838
assert isinstance(self.provider, PrimitiveProvider)
838839
# only fire if we actually used that provider to generate this observation
@@ -849,7 +850,7 @@ def on_observation(observation: Observation) -> None:
849850
# by this isinstance check)
850851
and isinstance(self.provider, PrimitiveProvider)
851852
# and the provider opted-in to observations
852-
and self.provider.add_observation_callback
853+
and self.provider.add_observability_callback
853854
)
854855
else nullcontext()
855856
)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
next_up,
6464
)
6565
from hypothesis.internal.intervalsets import IntervalSet
66-
from hypothesis.internal.observability import InfoObservationType, Observation
66+
from hypothesis.internal.observability import InfoObservationType, TestCaseObservation
6767

6868
if TYPE_CHECKING:
6969
from typing import TypeAlias
@@ -364,7 +364,7 @@ class PrimitiveProvider(abc.ABC):
364364
#:
365365
#: The opt-in behavior of observability is because enabling observability
366366
#: might increase runtime or memory usage.
367-
add_observation_callback: ClassVar[bool] = False
367+
add_observability_callback: ClassVar[bool] = False
368368

369369
def __init__(self, conjecturedata: Optional["ConjectureData"], /) -> None:
370370
self._cd = conjecturedata
@@ -554,7 +554,7 @@ def observe_information_messages(
554554
assert lifetime in ("test_case", "test_function")
555555
yield from []
556556

557-
def on_observation(self, observation: Observation) -> None: # noqa: B027
557+
def on_observation(self, observation: TestCaseObservation) -> None: # noqa: B027
558558
"""
559559
Called at the end of each test case which uses this provider, with the same
560560
``observation["type"] == "test_case"`` observation that is passed to
@@ -564,7 +564,7 @@ def on_observation(self, observation: Observation) -> None: # noqa: B027
564564
.. important::
565565
566566
For |PrimitiveProvider.on_observation| to be called by Hypothesis,
567-
|PrimitiveProvider.add_observation_callback| must be set to ``True``,
567+
|PrimitiveProvider.add_observability_callback| must be set to ``True``,
568568
569569
|PrimitiveProvider.on_observation| is explicitly opt-in, as enabling
570570
observability might increase runtime or memory usage.

hypothesis-python/tests/conjecture/test_alt_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def test_replay_choices():
722722

723723

724724
class ObservationProvider(TrivialProvider):
725-
add_observation_callback = True
725+
add_observability_callback = True
726726

727727
def __init__(self, conjecturedata: "ConjectureData", /) -> None:
728728
super().__init__(conjecturedata)

0 commit comments

Comments
 (0)