diff --git a/django-stubs/db/models/manager.pyi b/django-stubs/db/models/manager.pyi index f0ba75b..bac3672 100644 --- a/django-stubs/db/models/manager.pyi +++ b/django-stubs/db/models/manager.pyi @@ -4,6 +4,7 @@ from django.db.models.base import Model from django.db.models.query import QuerySet _T = TypeVar("_T", bound=Model, covariant=True) +_Self = TypeVar('_Self', bound='BaseManager') class BaseManager(QuerySet[_T]): creation_counter: int = ... @@ -16,7 +17,7 @@ class BaseManager(QuerySet[_T]): def deconstruct(self) -> Tuple[bool, str, None, Tuple, Dict[str, int]]: ... def check(self, **kwargs: Any) -> List[Any]: ... @classmethod - def from_queryset(cls, queryset_class: Any, class_name: Optional[Any] = ...): ... + def from_queryset(cls: Type[_Self], queryset_class: Any, class_name: Optional[Any] = ...) -> Type[_Self]: ... @classmethod def _get_queryset_methods(cls, queryset_class: type) -> Dict[str, Any]: ... def contribute_to_class(self, model: Type[Model], name: str) -> None: ... diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index e3098bf..a4dfffb 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -35,7 +35,7 @@ IGNORED_ERRORS = { # settings re.compile(r'Module has no attribute "[A-Z_]+"'), # attributes assigned to test functions - re.compile(r'"Callable\[\[(Any(, )?)+\], Any\]" has no attribute'), + re.compile(r'"Callable\[\[(Any(, )?)+(, VarArg\(Any\))?(, KwArg\(Any\))?\], Any\]" has no attribute'), # assign empty tuple re.compile(r'Incompatible types in assignment \(expression has type "Tuple\[\]", ' r'variable has type "Tuple\[[A-Za-z, ]+\]"'), @@ -70,6 +70,19 @@ IGNORED_ERRORS = { 'builtin_server': [ 'has no attribute "getvalue"' ], + 'custom_lookups': [ + 'in base class "SQLFuncMixin"' + ], + 'custom_managers': [ + '_filter_CustomQuerySet', + '_filter_CustomManager', + re.compile(r'Cannot determine type of \'(abstract_persons|cars|plain_manager)\''), + # TODO: remove after 'objects' and '_default_manager' are handled in the plugin + 'Incompatible types in assignment (expression has type "CharField", ' + + 'base class "Model" defined the type as "Manager[Model]")', + # TODO: remove after from_queryset() handled in the plugin + 'Invalid base class' + ], 'csrf_tests': [ 'Incompatible types in assignment (expression has type "property", ' + 'base class "HttpRequest" defined the type as "QueryDict")' @@ -167,8 +180,8 @@ TESTS_DIRS = [ 'context_processors', 'csrf_tests', 'custom_columns', - # TODO: 'custom_lookups', - # TODO: 'custom_managers', + 'custom_lookups', + 'custom_managers', 'custom_methods', 'custom_migration_operations', 'custom_pk',