From a035c964828bdc0c30041baf67d425493ff1301b Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 30 Sep 2024 19:33:02 -0700 Subject: [PATCH] Make `EventQuerySet` Generic (#170) --- pghistory/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pghistory/models.py b/pghistory/models.py index 5e8f60d..d228a64 100644 --- a/pghistory/models.py +++ b/pghistory/models.py @@ -1,5 +1,6 @@ import uuid import warnings +from typing import TYPE_CHECKING, TypeVar import django from django.apps import apps @@ -11,6 +12,8 @@ from pghistory import core, utils +_M = TypeVar("_M", bound=models.Model) + # This class is to preserve backwards compatibility with migrations PGHistoryJSONField = utils.JSONField @@ -129,7 +132,13 @@ def get_compiler(self, *args, **kwargs): return compiler -class EventQuerySet(models.QuerySet): +if TYPE_CHECKING: + _EventQuerySetBase = models.QuerySet[_M] +else: + _EventQuerySetBase = models.QuerySet + + +class EventQuerySet(_EventQuerySetBase): """QuerySet with support for proxy fields""" def __init__(self, model=None, query=None, using=None, hints=None):