From 29e2b65c8b0b58c62531e34b4e6ac539b4935cd4 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 9 Sep 2022 15:16:22 +0100 Subject: [PATCH] Improve Flake8 config (#1149) --- django_stubs_ext/django_stubs_ext/annotations.py | 3 ++- mypy_django_plugin/transformers/functional.py | 2 +- mypy_django_plugin/transformers/models.py | 13 +++++++++---- setup.cfg | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/django_stubs_ext/django_stubs_ext/annotations.py b/django_stubs_ext/django_stubs_ext/annotations.py index 3c819af..d276184 100644 --- a/django_stubs_ext/django_stubs_ext/annotations.py +++ b/django_stubs_ext/django_stubs_ext/annotations.py @@ -16,7 +16,8 @@ class Annotations(Generic[_Annotations]): _T = TypeVar("_T", bound=Model) WithAnnotations = Annotated[_T, Annotations[_Annotations]] -"""Alias to make it easy to annotate the model `_T` as having annotations `_Annotations` (a `TypedDict` or `Any` if not provided). +"""Alias to make it easy to annotate the model `_T` as having annotations +`_Annotations` (a `TypedDict` or `Any` if not provided). Use as `WithAnnotations[MyModel]` or `WithAnnotations[MyModel, MyTypedDict]`. """ diff --git a/mypy_django_plugin/transformers/functional.py b/mypy_django_plugin/transformers/functional.py index ebea7cc..005f7da 100644 --- a/mypy_django_plugin/transformers/functional.py +++ b/mypy_django_plugin/transformers/functional.py @@ -18,7 +18,7 @@ def resolve_str_promise_attribute(ctx: AttributeContext) -> MypyType: ctx.api.fail(f'Cannot resolve the attribute of "{ctx.type}"', ctx.context, code=ATTR_DEFINED) return AnyType(TypeOfAny.from_error) - str_info = helpers.lookup_fully_qualified_typeinfo(helpers.get_typechecker_api(ctx), f"builtins.str") + str_info = helpers.lookup_fully_qualified_typeinfo(helpers.get_typechecker_api(ctx), "builtins.str") assert str_info is not None str_type = Instance(str_info, []) return analyze_member_access( diff --git a/mypy_django_plugin/transformers/models.py b/mypy_django_plugin/transformers/models.py index 484cc87..adedabe 100644 --- a/mypy_django_plugin/transformers/models.py +++ b/mypy_django_plugin/transformers/models.py @@ -128,7 +128,7 @@ class ModelClassInitializer: for method_name in MANAGER_METHODS_RETURNING_QUERYSET: helpers.add_new_sym_for_info(manager_info, name=method_name, sym_type=AnyType(TypeOfAny.special_form)) - manager_info.metadata["django"] = django_metadata = { + manager_info.metadata["django"] = { "any_fallback_manager": True, "from_queryset_manager": fallback_queryset.fullname, } @@ -521,7 +521,11 @@ class AddRelatedManagers(ModelClassInitializer): ) related_model_fullname = related_model_cls.__module__ + "." + related_model_cls.__name__ self.ctx.api.fail( - f"Couldn't resolve related manager for relation {relation.name!r} (from {related_model_fullname}.{relation.field}).", + ( + "Couldn't resolve related manager for relation " + f"{relation.name!r} (from {related_model_fullname}." + f"{relation.field})." + ), self.ctx.cls, code=MANAGER_MISSING, ) @@ -539,8 +543,9 @@ class AddRelatedManagers(ModelClassInitializer): ) continue - # The reverse manager we're looking for doesn't exist. So we create it. - # The (default) reverse manager type is built from a RelatedManager and the default manager on the related model + # The reverse manager we're looking for doesn't exist. So we + # create it. The (default) reverse manager type is built from a + # RelatedManager and the default manager on the related model parametrized_related_manager_type = Instance(related_manager_info, [Instance(related_model_info, [])]) default_manager_type = default_manager.type assert default_manager_type is not None diff --git a/setup.cfg b/setup.cfg index 842d130..15228dd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,7 @@ [flake8] exclude = .*/ -select = F401, Y +extend-ignore = E203 +extend-select = F401, Y max_line_length = 120 per-file-ignores = *__init__.pyi: F401