Ensure that all registered checks return a list of CheckMessage (#508)

* Ensure that all registered checks return a list of CheckMessage

This changes missing and Any return types on registered checks to always
return "List[CheckMessage]".

In many cases, check functions were already annotated to return in a more
specific type than CheckMessage (e.g. Error). In these cases, it's assumed
that the existing annotation is correct, and the more specific type is kept.

* Update model_checks.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Brian Helba
2021-05-01 03:34:38 -07:00
committed by GitHub
parent e4de8453cf
commit 619823d497
5 changed files with 17 additions and 13 deletions

View File

@@ -1,14 +1,12 @@
from typing import Any, List, Union, Optional, Sequence
from typing import Any, List, Optional, Sequence
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import CheckMessage, Error
from django.apps.config import AppConfig
_CheckError = Union[str, Error]
def check_admin_app(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[_CheckError]: ...
def check_dependencies(**kwargs: Any) -> List[_CheckError]: ...
def check_admin_app(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...
def check_dependencies(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...
class BaseModelAdminChecks:
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> List[CheckMessage]: ...