Skip to content

Commit

Permalink
Improve Flake8 config (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Sep 9, 2022
1 parent abd0609 commit 29e2b65
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion django_stubs_ext/django_stubs_ext/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
"""
2 changes: 1 addition & 1 deletion mypy_django_plugin/transformers/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 9 additions & 4 deletions mypy_django_plugin/transformers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_or_create_manager_with_any_fallback(self, related_manager: bool = False)
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,
}
Expand Down Expand Up @@ -521,7 +521,11 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
)
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,
)
Expand All @@ -539,8 +543,9 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
)
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
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 29e2b65

Please sign in to comment.