Skip to content

Commit

Permalink
Move ModelBase.objects declaration to Model.objects, for mypy 1.5.0
Browse files Browse the repository at this point in the history
mypy 1.5.0 was fixed to understand that metaclass attributes take
precedence over attributes in the regular class.  So we need to
declare `objects` in the regular class to allow it to be overridden in
subclasses.

Fixes typeddjango#1648.

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Aug 10, 2023
1 parent 325006c commit dc23e4e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django-stubs/db/models/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class ModelState:
fields_cache: ModelStateFieldsCacheDescriptor

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):
objects: BaseManager[Self] = ...

DoesNotExist: Final[type[ObjectDoesNotExist]]
MultipleObjectsReturned: Final[type[BaseMultipleObjectsReturned]]

Expand Down

0 comments on commit dc23e4e

Please sign in to comment.