Skip to content

Commit 5832605

Browse files
authored
Remove warning about unsupported expression types (#266)
* remove warning about unsupported expression for _meta.get_field() * lint
1 parent 31e7950 commit 5832605

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

mypy_django_plugin/lib/helpers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ def make_typeddict(api: CheckerPluginInterface, fields: 'OrderedDict[str, MypyTy
259259
return typed_dict_type
260260

261261

262-
def resolve_string_attribute_value(attr_expr: Expression, ctx: Union[FunctionContext, MethodContext],
263-
django_context: 'DjangoContext') -> Optional[str]:
262+
def resolve_string_attribute_value(attr_expr: Expression, django_context: 'DjangoContext') -> Optional[str]:
264263
if isinstance(attr_expr, StrExpr):
265264
return attr_expr.value
266265

@@ -270,8 +269,6 @@ def resolve_string_attribute_value(attr_expr: Expression, ctx: Union[FunctionCon
270269
if isinstance(attr_expr.expr, NameExpr) and attr_expr.expr.fullname == 'django.conf.settings':
271270
if hasattr(django_context.settings, member_name):
272271
return getattr(django_context.settings, member_name)
273-
274-
ctx.api.fail(f'Expression of type {type(attr_expr).__name__!r} is not supported', ctx.context)
275272
return None
276273

277274

mypy_django_plugin/transformers/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def return_proper_field_type_from_get_field(ctx: MethodContext, django_context:
3636
if field_name_expr is None:
3737
return ctx.default_return_type
3838

39-
field_name = helpers.resolve_string_attribute_value(field_name_expr, ctx, django_context)
39+
field_name = helpers.resolve_string_attribute_value(field_name_expr, django_context)
4040
if field_name is None:
4141
return ctx.default_return_type
4242

mypy_django_plugin/transformers/querysets.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import OrderedDict
2-
from typing import List, Optional, Sequence, Type, Union
2+
from typing import List, Optional, Sequence, Type
33

44
from django.core.exceptions import FieldError
55
from django.db.models.base import Model
@@ -62,7 +62,7 @@ def get_field_type_from_lookup(ctx: MethodContext, django_context: DjangoContext
6262

6363
def get_values_list_row_type(ctx: MethodContext, django_context: DjangoContext, model_cls: Type[Model],
6464
flat: bool, named: bool) -> MypyType:
65-
field_lookups = resolve_field_lookups(ctx.args[0], ctx, django_context)
65+
field_lookups = resolve_field_lookups(ctx.args[0], django_context)
6666
if field_lookups is None:
6767
return AnyType(TypeOfAny.from_error)
6868

@@ -148,11 +148,10 @@ def extract_proper_type_queryset_values_list(ctx: MethodContext, django_context:
148148
return helpers.reparametrize_instance(ctx.default_return_type, [model_type, row_type])
149149

150150

151-
def resolve_field_lookups(lookup_exprs: Sequence[Expression], ctx: Union[FunctionContext, MethodContext],
152-
django_context: DjangoContext) -> Optional[List[str]]:
151+
def resolve_field_lookups(lookup_exprs: Sequence[Expression], django_context: DjangoContext) -> Optional[List[str]]:
153152
field_lookups = []
154153
for field_lookup_expr in lookup_exprs:
155-
field_lookup = helpers.resolve_string_attribute_value(field_lookup_expr, ctx, django_context)
154+
field_lookup = helpers.resolve_string_attribute_value(field_lookup_expr, django_context)
156155
if field_lookup is None:
157156
return None
158157
field_lookups.append(field_lookup)
@@ -172,7 +171,7 @@ def extract_proper_type_queryset_values(ctx: MethodContext, django_context: Djan
172171
if model_cls is None:
173172
return ctx.default_return_type
174173

175-
field_lookups = resolve_field_lookups(ctx.args[0], ctx, django_context)
174+
field_lookups = resolve_field_lookups(ctx.args[0], django_context)
176175
if field_lookups is None:
177176
return AnyType(TypeOfAny.from_error)
178177

scripts/enabled_test_modules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
re.compile(r'has no attribute ("|\')_[a-zA-Z_]+("|\')'),
3232
"'Settings' object has no attribute",
3333
'**Dict',
34-
re.compile(r"Expression of type '.*' is not supported"),
3534
'has incompatible type "object"',
3635
'undefined in superclass',
3736
'Argument after ** must be a mapping',

0 commit comments

Comments
 (0)