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

Update _default_manager and _base_manager to be Manager #2022

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions django-stubs/db/models/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from django.core.checks.messages import CheckMessage
from django.core.exceptions import MultipleObjectsReturned as BaseMultipleObjectsReturned
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db.models import BaseConstraint, Field, QuerySet
from django.db.models.manager import BaseManager, Manager
from django.db.models.manager import Manager
from django.db.models.options import Options
from typing_extensions import Self

Expand All @@ -24,9 +24,9 @@ class ModelState:

class ModelBase(type):
@property
def _default_manager(cls: type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc]
def _default_manager(cls: type[_Self]) -> Manager[_Self]: ... # type: ignore[misc]
@property
def _base_manager(cls: type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc]
def _base_manager(cls: type[_Self]) -> Manager[_Self]: ... # type: ignore[misc]

class Model(metaclass=ModelBase):
# Note: these two metaclass generated attributes don't really exist on the 'Model'
Expand Down
14 changes: 7 additions & 7 deletions tests/typecheck/managers/test_managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class Base(Generic[_T]):
def __init__(self, model_cls: Type[_T]) -> None:
self.model_cls = model_cls
reveal_type(self.model_cls._default_manager) # N: Revealed type is "django.db.models.manager.BaseManager[_T`1]"
reveal_type(self.model_cls._default_manager) # N: Revealed type is "django.db.models.manager.Manager[_T`1]"
class MyModel(models.Model):
pass
class Child(Base[MyModel]):
Expand All @@ -59,7 +59,7 @@
main: |
from myapp.models import Base, MyModel
base_instance = Base(MyModel)
reveal_type(base_instance.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.BaseManager[myapp.models.MyModel]"
reveal_type(base_instance.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.Manager[myapp.models.MyModel]"
installed_apps:
- myapp
files:
Expand All @@ -73,12 +73,12 @@
class Base(Generic[_T]):
def __init__(self, model_cls: Type[_T]) -> None:
self.model_cls = model_cls
reveal_type(self.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.BaseManager[_T`1]"
reveal_type(self.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.Manager[_T`1]"
class MyModel(models.Model):
pass
class Child(Base[MyModel]):
def method(self) -> None:
reveal_type(self.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.BaseManager[myapp.models.MyModel]"
reveal_type(self.model_cls._base_manager) # N: Revealed type is "django.db.models.manager.Manager[myapp.models.MyModel]"

- case: if_custom_manager_defined_it_is_set_to_default_manager
main: |
Expand Down Expand Up @@ -547,12 +547,12 @@
myapp/models:36: note: Revealed type is "django.db.models.manager.Manager[myapp.models.User]"
myapp/models:37: note: Revealed type is "django.db.models.manager.Manager[myapp.models.User]"
myapp/models:39: note: Revealed type is "myapp.models.UnknownManager[myapp.models.Booking]"
myapp/models:40: note: Revealed type is "django.db.models.manager.BaseManager[myapp.models.Booking]"
myapp/models:40: note: Revealed type is "django.db.models.manager.Manager[myapp.models.Booking]"
myapp/models:42: note: Revealed type is "myapp.models.UnknownManager[myapp.models.TwoUnresolvable]"
myapp/models:43: note: Revealed type is "myapp.models.UnknownManager[myapp.models.TwoUnresolvable]"
myapp/models:44: note: Revealed type is "django.db.models.manager.BaseManager[myapp.models.TwoUnresolvable]"
myapp/models:44: note: Revealed type is "django.db.models.manager.Manager[myapp.models.TwoUnresolvable]"
myapp/models:46: note: Revealed type is "myapp.models.UnknownManager[myapp.models.InvisibleUnresolvable]"
myapp/models:47: note: Revealed type is "django.db.models.manager.BaseManager[myapp.models.InvisibleUnresolvable]"
myapp/models:47: note: Revealed type is "django.db.models.manager.Manager[myapp.models.InvisibleUnresolvable]"
myapp/models:49: note: Revealed type is "myapp.models.UnknownRelatedManager[myapp.models.Booking]"
myapp/models:50: note: Revealed type is "myapp.models.UnknownRelatedManager[myapp.models.Booking]"
myapp/models:53: note: Revealed type is "def () -> myapp.models.UnknownQuerySet[myapp.models.Booking, myapp.models.Booking]"
Expand Down
Loading