From b6af2b29099598fe5bba1c7e51abbe7e6e58de3d Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:51:44 +0200 Subject: [PATCH] Make return type of `from_model` parameterized with respect to `model` --- hypothesis-python/src/hypothesis/extra/django/_impl.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hypothesis-python/src/hypothesis/extra/django/_impl.py b/hypothesis-python/src/hypothesis/extra/django/_impl.py index 799c15d242..fb368fb566 100644 --- a/hypothesis-python/src/hypothesis/extra/django/_impl.py +++ b/hypothesis-python/src/hypothesis/extra/django/_impl.py @@ -11,7 +11,7 @@ import sys import unittest from functools import partial -from typing import TYPE_CHECKING, Optional, Type, Union +from typing import TYPE_CHECKING, Optional, Type, TypeVar, Union from django import forms as df, test as dt from django.contrib.staticfiles import testing as dst @@ -30,6 +30,8 @@ else: EllipsisType = type(Ellipsis) +ModelT = TypeVar("ModelT", bound=dm.Model) + class HypothesisTestCase: def setup_example(self): @@ -64,8 +66,8 @@ class StaticLiveServerTestCase(HypothesisTestCase, dst.StaticLiveServerTestCase) @defines_strategy() def from_model( - model: Type[dm.Model], /, **field_strategies: Union[st.SearchStrategy, EllipsisType] -) -> st.SearchStrategy: + model: Type[ModelT], /, **field_strategies: Union[st.SearchStrategy, EllipsisType] +) -> st.SearchStrategy[ModelT]: """Return a strategy for examples of ``model``. .. warning::