Skip to content

Commit 77c2e6c

Browse files
committed
Add minimal annotations to unit tests
These annotations are sufficient to pass mypy inspection if mypy is configured to allow unannotated functions.
1 parent 9dbab39 commit 77c2e6c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import ClassVar
3+
from typing import ClassVar, TypeVar
44

55
from django.db import models
66
from django.db.models import Manager
@@ -21,6 +21,8 @@
2121
from tests.fields import MutableField
2222
from tests.managers import CustomSoftDeleteManager
2323

24+
ModelT = TypeVar('ModelT', bound=models.Model, covariant=True)
25+
2426

2527
class InheritanceManagerTestRelated(models.Model):
2628
pass
@@ -122,7 +124,7 @@ class DoubleMonitored(models.Model):
122124

123125

124126
class Status(StatusModel):
125-
STATUS = Choices(
127+
STATUS: Choices[str] = Choices(
126128
("active", _("active")),
127129
("deleted", _("deleted")),
128130
("on_hold", _("on hold")),
@@ -178,7 +180,8 @@ class Post(models.Model):
178180
public: ClassVar[QueryManager[Post]] = QueryManager(published=True)
179181
public_confirmed: ClassVar[QueryManager[Post]] = QueryManager(
180182
models.Q(published=True) & models.Q(confirmed=True))
181-
public_reversed = QueryManager(published=True).order_by("-order")
183+
public_reversed: QueryManager[Post] = QueryManager(
184+
published=True).order_by("-order")
182185

183186
class Meta:
184187
ordering = ("order",)
@@ -240,7 +243,7 @@ class TrackedFK(models.Model):
240243

241244
class TrackedAbstract(AbstractTracked):
242245
name = models.CharField(max_length=20)
243-
number = models.IntegerField()
246+
number = models.IntegerField() # type: ignore[assignment]
244247
mutable = MutableField(default=None)
245248

246249
tracker = FieldTracker()

0 commit comments

Comments
 (0)