From f4cf7f2847ea59744bc081916eb9e24c5ea794cd Mon Sep 17 00:00:00 2001 From: Clouds Date: Sat, 5 Nov 2022 14:41:34 +0800 Subject: [PATCH] move _default_manager to ModelBase (#1150) * move _default_manager to ModelBase * fix for mypy check * Update base.pyi * Update base.pyi --- django-stubs/db/models/base.pyi | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 9c189d593..d9beee070 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -5,7 +5,6 @@ from django.core.exceptions import MultipleObjectsReturned as BaseMultipleObject from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db.models.manager import BaseManager from django.db.models.options import Options -from django.utils.functional import classproperty _Self = TypeVar("_Self", bound="Model") @@ -16,20 +15,19 @@ class ModelState: adding: bool = ... fields_cache: ModelStateFieldsCacheDescriptor = ... -class ModelBase(type): ... +class ModelBase(type): + @property + def objects(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] + @property + def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] + @property + def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] class Model(metaclass=ModelBase): class DoesNotExist(ObjectDoesNotExist): ... class MultipleObjectsReturned(BaseMultipleObjectsReturned): ... class Meta: ... _meta: Options[Any] - @classproperty - @classmethod - def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... - @classproperty - @classmethod - def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... - objects: BaseManager[Any] pk: Any = ... _state: ModelState def __init__(self: _Self, *args: Any, **kwargs: Any) -> None: ...