Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that Manager.from_queryset() handles invalid argument types #1731

Merged
merged 6 commits into from
Oct 18, 2023
25 changes: 25 additions & 0 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,28 @@
...

StrCallable = BaseManager.from_queryset(ModelQuerySet, class_name=str(1))

- case: test_queryset_arg_as_unsupported_expressions
main: |
from typing import Union, Generic, TypeVar
from typing_extensions import TypeAlias
from django.db import models
from django.db.models.manager import Manager

class QS1(models.QuerySet[models.Model]):
...
class QS2(models.QuerySet[models.Model]):
...

Alias: TypeAlias = Union[QS1, QS2]
reveal_type(Manager[models.Model].from_queryset(Alias))

T = TypeVar("T")
class NonQSGeneric(Generic[T]):
...
reveal_type(Manager[models.Model].from_queryset(NonQSGeneric[int]))
out: |
main:12: note: Revealed type is "Type[django.db.models.manager.Manager[django.db.models.base.Model]]"
main:12: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "<typing special form>"; expected "Type[_QuerySet[Model, Model]]" [arg-type]
main:17: note: Revealed type is "Type[django.db.models.manager.Manager[django.db.models.base.Model]]"
main:17: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "Type[NonQSGeneric[Any]]"; expected "Type[_QuerySet[Model, Model]]" [arg-type]