Skip to content

Commit

Permalink
Repro test case for phantom errors in typeddjango#709
Browse files Browse the repository at this point in the history
  • Loading branch information
flaeppe committed Jan 3, 2022
1 parent 49bed6c commit 7070b85
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@
class MyModel(models.Model):
objects = NewManager()
- case: from_queryset_queryset_imported_from_other_module
main: |
from myapp.models import MyModel
reveal_type(MyModel().objects) # N: Revealed type is "myapp.models.NewManager[myapp.models.MyModel]"
reveal_type(MyModel().objects.get()) # N: Revealed type is "myapp.models.MyModel*"
reveal_type(MyModel().objects.queryset_method()) # N: Revealed type is "myapp.querysets.ModelQuerySet"
reveal_type(MyModel().objects.queryset_method_2()) # N: Revealed type is "typing.Iterable[Any]"
reveal_type(MyModel.objects.filter(id=1).queryset_method()) # N: Revealed type is "myapp.querysets.ModelQuerySet"
reveal_type(MyModel.objects.filter(id=1)) # N: Revealed type is "myapp.querysets.ModelQuerySet[myapp.models.MyModel*]"
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/querysets.py
content: |
from typing import TYPE_CHECKING, Iterable
from django.db import models
if TYPE_CHECKING:
from .models import MyModel
class ModelQuerySet(models.QuerySet["MyModel"]):
def queryset_method(self) -> "ModelQuerySet":
return self.filter()
def queryset_method_2(self) -> Iterable:
return []
- path: myapp/models.py
content: |
from django.db import models
from django.db.models.manager import BaseManager
from .querysets import ModelQuerySet
NewManager = BaseManager.from_queryset(ModelQuerySet)
class MyModel(models.Model):
objects = NewManager()
- case: from_queryset_with_manager
main: |
from myapp.models import MyModel
Expand Down

0 comments on commit 7070b85

Please sign in to comment.