From bfa77efef5eccd712219041247466ef247137a6f Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Thu, 18 Jul 2019 04:02:32 +0300 Subject: [PATCH] one more edge case for values() --- mypy_django_plugin/django/context.py | 2 +- mypy_django_plugin/transformers/querysets.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mypy_django_plugin/django/context.py b/mypy_django_plugin/django/context.py index 2d73888..ea2fc8c 100644 --- a/mypy_django_plugin/django/context.py +++ b/mypy_django_plugin/django/context.py @@ -106,7 +106,7 @@ class DjangoLookupsContext: def __init__(self, django_context: 'DjangoContext'): self.django_context = django_context - def resolve_lookup(self, model_cls: Type[Model], lookup: str) -> Optional[Field]: + def resolve_lookup(self, model_cls: Type[Model], lookup: str) -> Field: query = Query(model_cls) lookup_parts, field_parts, is_expression = query.solve_lookup_type(lookup) if lookup_parts: diff --git a/mypy_django_plugin/transformers/querysets.py b/mypy_django_plugin/transformers/querysets.py index 12aadf4..7188014 100644 --- a/mypy_django_plugin/transformers/querysets.py +++ b/mypy_django_plugin/transformers/querysets.py @@ -153,8 +153,11 @@ def resolve_field_lookups(lookup_exprs: Sequence[Expression], ctx: Union[Functio def extract_proper_type_queryset_values(ctx: MethodContext, django_context: DjangoContext) -> MypyType: + # queryset method assert isinstance(ctx.type, Instance) - assert isinstance(ctx.type.args[0], Instance) + # if queryset of non-instance type + if not isinstance(ctx.type.args[0], Instance): + return AnyType(TypeOfAny.from_omitted_generics) model_type = ctx.type.args[0] model_cls = django_context.get_model_class_by_fullname(model_type.type.fullname())