From 33097997c0ef2f3aecdc9ebb43d77f036cfa3711 Mon Sep 17 00:00:00 2001 From: Clouds Date: Wed, 14 Sep 2022 03:23:37 +0800 Subject: [PATCH 1/4] move _default_manager to ModelBase --- django-stubs/db/models/base.pyi | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index d0756e2e8..07d2bea48 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,19 +15,17 @@ class ModelState: adding: bool = ... fields_cache: ModelStateFieldsCacheDescriptor = ... -class ModelBase(type): ... +class ModelBase(type): + @property + def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... + @property + def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... 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 From c82afda33d481392e2c2eff8762c2b9e7b529dbc Mon Sep 17 00:00:00 2001 From: Clouds Date: Wed, 14 Sep 2022 04:15:02 +0800 Subject: [PATCH 2/4] fix for mypy check --- django-stubs/db/models/base.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 07d2bea48..c712691f2 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -7,6 +7,7 @@ from django.db.models.manager import BaseManager from django.db.models.options import Options _Self = TypeVar("_Self", bound="Model") +_Model = TypeVar("_Model") class ModelStateFieldsCacheDescriptor: ... @@ -17,9 +18,9 @@ class ModelState: class ModelBase(type): @property - def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... + def _default_manager(cls: Type[_Model]) -> BaseManager[_Model]: ... @property - def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... + def _base_manager(cls: Type[_Model]) -> BaseManager[_Model]: ... class Model(metaclass=ModelBase): class DoesNotExist(ObjectDoesNotExist): ... From 9e51c381111509c87ef99c98b838000867e49520 Mon Sep 17 00:00:00 2001 From: Clouds Date: Wed, 14 Sep 2022 21:46:36 +0800 Subject: [PATCH 3/4] Update base.pyi --- django-stubs/db/models/base.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index c712691f2..2148b3f32 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -7,7 +7,6 @@ from django.db.models.manager import BaseManager from django.db.models.options import Options _Self = TypeVar("_Self", bound="Model") -_Model = TypeVar("_Model") class ModelStateFieldsCacheDescriptor: ... @@ -18,16 +17,17 @@ class ModelState: class ModelBase(type): @property - def _default_manager(cls: Type[_Model]) -> BaseManager[_Model]: ... + def objects(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore @property - def _base_manager(cls: Type[_Model]) -> BaseManager[_Model]: ... + def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore + @property + def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore class Model(metaclass=ModelBase): class DoesNotExist(ObjectDoesNotExist): ... class MultipleObjectsReturned(BaseMultipleObjectsReturned): ... class Meta: ... _meta: Options[Any] - objects: BaseManager[Any] pk: Any = ... _state: ModelState def __init__(self: _Self, *args, **kwargs) -> None: ... From d87f75a6955ce6a6bfa7ec6cbc0a28a85b25f28d Mon Sep 17 00:00:00 2001 From: Clouds Date: Thu, 15 Sep 2022 01:29:06 +0800 Subject: [PATCH 4/4] Update base.pyi --- django-stubs/db/models/base.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 2148b3f32..7eb9dd87e 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -17,11 +17,11 @@ class ModelState: class ModelBase(type): @property - def objects(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore + def objects(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] @property - def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore + def _default_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] @property - def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore + def _base_manager(cls: Type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] class Model(metaclass=ModelBase): class DoesNotExist(ObjectDoesNotExist): ...