From 3ccecebe3fcbc27cafee8c63fa586019befb7251 Mon Sep 17 00:00:00 2001 From: Oleg Nykolyn Date: Thu, 31 Jan 2019 21:35:35 +0200 Subject: [PATCH] Fix and uncomment tests. --- django-stubs/db/models/query.pyi | 19 +++++-------------- scripts/typecheck_tests.py | 4 +++- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index f62929f..47d38f2 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -144,26 +144,17 @@ class RawQuerySet(Iterable[_T], Sized): def using(self, alias: Optional[str]) -> RawQuerySet[_T]: ... class Prefetch(object): - def __init__(self, lookup, queryset=None, to_attr=None): - # `prefetch_through` is the path we traverse to perform the prefetch. - self.prefetch_through = lookup - # `prefetch_to` is the path to the attribute that stores the result. - self.prefetch_to = lookup - if queryset is not None and not issubclass(queryset._iterable_class, ModelIterable): - raise ValueError('Prefetch querysets cannot use values().') - if to_attr: - self.prefetch_to = LOOKUP_SEP.join(lookup.split(LOOKUP_SEP)[:-1] + [to_attr]) - - self.queryset = queryset - self.to_attr = to_attr - + def __init__(self, lookup: str, queryset: Optional[QuerySet]=None, to_attr: Optional[str]=None) -> None: ... def __getstate__(self) -> Dict[str, Any]: ... def add_prefix(self, prefix: str) -> None: ... def get_current_prefetch_to(self, level: int) -> str: ... def get_current_to_attr(self, level: int) -> Tuple[str,str]: ... def get_current_queryset(self, level) -> Optional[QuerySet]: ... -def prefetch_related_objects(model_instances: Iterable[_T], *related_lookups: str) -> None: ... +def prefetch_related_objects(model_instances: Iterable[_T], *related_lookups: Union[str, Prefetch]) -> None: ... +def get_prefetcher(instance: _T, through_attr: str, to_attr: str) -> Tuple[Any, Any, bool, bool]: ... + +class ModelIterable(Iterable[_T]): ... class InstanceCheckMeta(type): ... class EmptyQuerySet(metaclass=InstanceCheckMeta): ... diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index 1b10eb7..7f27204 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -55,6 +55,8 @@ IGNORED_ERROR_PATTERNS = [ 'Argument 1 to "bytes"', '"full_clean" of "Model" does not return a value', '"object" not callable', + 'Item "GenericForeignKey" of "Union[GenericForeignKey, Model, None]" has no attribute "read_by"', + 'Item "Model" of "Union[GenericForeignKey, Model, None]" has no attribute "read_by"', re.compile('Cannot determine type of \'(objects|stuff|specimens|normal_manager)\''), re.compile(r'"Callable\[\[(Any(, )?)+\], Any\]" has no attribute'), re.compile(r'"HttpResponseBase" has no attribute "[A-Za-z_]+"'), @@ -215,9 +217,9 @@ TESTS_DIRS = [ 'or_lookups', 'order_with_respect_to', 'ordering', + 'prefetch_related', 'pagination', # TODO: 'postgres_tests', - # TODO: 'prefetch_related', 'project_template', 'properties', 'proxy_model_inheritance',