Type hints in Hypothesis
========================

We ship type hints with Hypothesis itself. Any :PEP:`561`-compatible type-checker, such as :pypi:`mypy` or :pypi:`pyright`, will automatically pick up on them.

.. note::

    Hypothesis' type hints may make breaking changes between minor releases.

    We may also find more precise ways to describe the type of various interfaces, or change their type and runtime behaviour together in a way which is otherwise backwards-compatible. We often omit type hints for deprecated features or arguments, as an additional form of warning.

There are known issues with inferring the type of examples generated by |st.deferred|, |st.recursive|, |st.one_of|, |st.dictionaries|, and |st.fixed_dictionaries|. We're following proposed updates to Python's typing standards, but unfortunately the long-standing interfaces of these strategies cannot (yet) be statically typechecked.

Writing downstream type hints
-----------------------------

Projects that :doc:`provide Hypothesis strategies </reference/strategies>` and use type hints may wish to annotate their strategies too. For example:

.. code:: python

    def foo_strategy() -> SearchStrategy[Foo]: ...

|SearchStrategy| is the type of all strategy objects. It is a generic type, and covariant in the type of the examples it creates.  For example:

- ``integers()`` is of type ``SearchStrategy[int]``.
- ``lists(integers())`` is of type ``SearchStrategy[List[int]]``.
- ``SearchStrategy[Dog]`` is a subtype of ``SearchStrategy[Animal]`` if ``Dog`` is a subtype of ``Animal`` (as seems likely).
