Skip to content

Commit

Permalink
Avoid using Self as a type argument
Browse files Browse the repository at this point in the history
For some reason this fails when mypy has an empty cache, but passes
when the cache has been filled. Maybe it's a weird interaction
between the mypy core and the django-stubs plugin?
  • Loading branch information
mthuurne committed Mar 25, 2024
1 parent 03dddc8 commit eaff1f3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.db.models import Manager
from django.db.models.query_utils import DeferredAttribute
from django.utils.translation import gettext_lazy as _
from typing_extensions import Self

from model_utils import Choices
from model_utils.fields import MonitorField, SplitField, StatusField, UUIDField
Expand Down Expand Up @@ -37,7 +36,7 @@ class InheritanceManagerTestParent(models.Model):
related_self = models.OneToOneField(
"self", related_name="imtests_self", null=True,
on_delete=models.CASCADE)
objects: ClassVar[Manager[Self]] = InheritanceManager()
objects: ClassVar[InheritanceManager[InheritanceManagerTestParent]] = InheritanceManager()

def __str__(self):
return "{}({})".format(
Expand All @@ -49,7 +48,7 @@ def __str__(self):
class InheritanceManagerTestChild1(InheritanceManagerTestParent):
non_related_field_using_descriptor_2 = models.FileField(upload_to="test")
normal_field_2 = models.TextField()
objects: ClassVar[Manager[Self]] = InheritanceManager()
objects: ClassVar[InheritanceManager[InheritanceManagerTestParent]] = InheritanceManager()


class InheritanceManagerTestGrandChild1(InheritanceManagerTestChild1):
Expand Down Expand Up @@ -176,8 +175,8 @@ class Post(models.Model):
order = models.IntegerField()

objects = models.Manager()
public: ClassVar[QueryManager[Self]] = QueryManager(published=True)
public_confirmed: ClassVar[QueryManager[Self]] = QueryManager(
public: ClassVar[QueryManager[Post]] = QueryManager(published=True)
public_confirmed: ClassVar[QueryManager[Post]] = QueryManager(
models.Q(published=True) & models.Q(confirmed=True))
public_reversed = QueryManager(published=True).order_by("-order")

Expand Down Expand Up @@ -350,7 +349,7 @@ class SoftDeletable(SoftDeletableModel):
class CustomSoftDelete(SoftDeletableModel):
is_read = models.BooleanField(default=False)

objects: ClassVar[CustomSoftDeleteManager[Self]] = CustomSoftDeleteManager()
objects: ClassVar[CustomSoftDeleteManager[SoftDeletableModel]] = CustomSoftDeleteManager()


class StringyDescriptor:
Expand Down Expand Up @@ -394,7 +393,7 @@ class ModelWithCustomDescriptor(models.Model):

class BoxJoinModel(models.Model):
name = models.CharField(max_length=32)
objects: ClassVar[JoinManager[Self]] = JoinManager()
objects: ClassVar[JoinManager[BoxJoinModel]] = JoinManager()


class JoinItemForeignKey(models.Model):
Expand All @@ -404,7 +403,7 @@ class JoinItemForeignKey(models.Model):
null=True,
on_delete=models.CASCADE
)
objects: ClassVar[JoinManager[Self]] = JoinManager()
objects: ClassVar[JoinManager[JoinItemForeignKey]] = JoinManager()


class CustomUUIDModel(UUIDModel):
Expand Down

0 comments on commit eaff1f3

Please sign in to comment.