Remove warning about unsupported expression types (#266)

* remove warning about unsupported expression for _meta.get_field()

* lint
This commit is contained in:
Maksim Kurnikov
2019-12-12 08:20:52 +03:00
committed by GitHub
parent 31e795016f
commit 5832605053
4 changed files with 7 additions and 12 deletions

View File

@@ -259,8 +259,7 @@ def make_typeddict(api: CheckerPluginInterface, fields: 'OrderedDict[str, MypyTy
return typed_dict_type
def resolve_string_attribute_value(attr_expr: Expression, ctx: Union[FunctionContext, MethodContext],
django_context: 'DjangoContext') -> Optional[str]:
def resolve_string_attribute_value(attr_expr: Expression, django_context: 'DjangoContext') -> Optional[str]:
if isinstance(attr_expr, StrExpr):
return attr_expr.value
@@ -270,8 +269,6 @@ def resolve_string_attribute_value(attr_expr: Expression, ctx: Union[FunctionCon
if isinstance(attr_expr.expr, NameExpr) and attr_expr.expr.fullname == 'django.conf.settings':
if hasattr(django_context.settings, member_name):
return getattr(django_context.settings, member_name)
ctx.api.fail(f'Expression of type {type(attr_expr).__name__!r} is not supported', ctx.context)
return None

View File

@@ -36,7 +36,7 @@ def return_proper_field_type_from_get_field(ctx: MethodContext, django_context:
if field_name_expr is None:
return ctx.default_return_type
field_name = helpers.resolve_string_attribute_value(field_name_expr, ctx, django_context)
field_name = helpers.resolve_string_attribute_value(field_name_expr, django_context)
if field_name is None:
return ctx.default_return_type

View File

@@ -1,5 +1,5 @@
from collections import OrderedDict
from typing import List, Optional, Sequence, Type, Union
from typing import List, Optional, Sequence, Type
from django.core.exceptions import FieldError
from django.db.models.base import Model
@@ -62,7 +62,7 @@ def get_field_type_from_lookup(ctx: MethodContext, django_context: DjangoContext
def get_values_list_row_type(ctx: MethodContext, django_context: DjangoContext, model_cls: Type[Model],
flat: bool, named: bool) -> MypyType:
field_lookups = resolve_field_lookups(ctx.args[0], ctx, django_context)
field_lookups = resolve_field_lookups(ctx.args[0], django_context)
if field_lookups is None:
return AnyType(TypeOfAny.from_error)
@@ -148,11 +148,10 @@ def extract_proper_type_queryset_values_list(ctx: MethodContext, django_context:
return helpers.reparametrize_instance(ctx.default_return_type, [model_type, row_type])
def resolve_field_lookups(lookup_exprs: Sequence[Expression], ctx: Union[FunctionContext, MethodContext],
django_context: DjangoContext) -> Optional[List[str]]:
def resolve_field_lookups(lookup_exprs: Sequence[Expression], django_context: DjangoContext) -> Optional[List[str]]:
field_lookups = []
for field_lookup_expr in lookup_exprs:
field_lookup = helpers.resolve_string_attribute_value(field_lookup_expr, ctx, django_context)
field_lookup = helpers.resolve_string_attribute_value(field_lookup_expr, django_context)
if field_lookup is None:
return None
field_lookups.append(field_lookup)
@@ -172,7 +171,7 @@ def extract_proper_type_queryset_values(ctx: MethodContext, django_context: Djan
if model_cls is None:
return ctx.default_return_type
field_lookups = resolve_field_lookups(ctx.args[0], ctx, django_context)
field_lookups = resolve_field_lookups(ctx.args[0], django_context)
if field_lookups is None:
return AnyType(TypeOfAny.from_error)

View File

@@ -31,7 +31,6 @@ IGNORED_ERRORS = {
re.compile(r'has no attribute ("|\')_[a-zA-Z_]+("|\')'),
"'Settings' object has no attribute",
'**Dict',
re.compile(r"Expression of type '.*' is not supported"),
'has incompatible type "object"',
'undefined in superclass',
'Argument after ** must be a mapping',