Skip to content

Commit

Permalink
types: Avoid issues with objects override on subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Jan 23, 2025
1 parent 114481b commit 8cfdde8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions testapp/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import TypeVar, ClassVar
from typing_extensions import Self

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import ForeignKey, PositiveIntegerField, CharField
from typedmodels.models import TypedModel
from typedmodels.models import TypedModel, TypedModelManager


class UniqueIdentifier(models.Model):
Expand Down Expand Up @@ -123,10 +126,14 @@ class Child2(Parent):
pass


class Employee(TypedModel):
class EmployeeManager(TypedModelManager):
pass


class Employee(TypedModel):
objects: ClassVar[EmployeeManager] = EmployeeManager()


class Developer(Employee):
name = models.CharField(max_length=255, null=True)

Expand All @@ -139,5 +146,4 @@ class Manager(Employee):
def typed_queryset() -> None:
# This isn't actually called, but it's here for the mypy check to ensure that type hinting works correctly.
queryset = Animal.objects.filter(pk=1)
reveal_type(queryset) # QuerySet[Animal]
queryset.filter(name="lynx") # works, because Animal has this field
2 changes: 1 addition & 1 deletion typedmodels/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.15.0b2"
__version__ = "0.15.0b3"
2 changes: 1 addition & 1 deletion typedmodels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

reveal_type = print

T = TypeVar("T", bound="TypedModel")
T = TypeVar("T", bound="TypedModel", covariant=True)


class TypedModelManager(models.Manager[T]):
Expand Down

0 comments on commit 8cfdde8

Please sign in to comment.