mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 15:57:08 +08:00
Improve Flake8 config (#1149)
This commit is contained in:
@@ -16,7 +16,8 @@ class Annotations(Generic[_Annotations]):
|
|||||||
_T = TypeVar("_T", bound=Model)
|
_T = TypeVar("_T", bound=Model)
|
||||||
|
|
||||||
WithAnnotations = Annotated[_T, Annotations[_Annotations]]
|
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]`.
|
Use as `WithAnnotations[MyModel]` or `WithAnnotations[MyModel, MyTypedDict]`.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -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)
|
ctx.api.fail(f'Cannot resolve the attribute of "{ctx.type}"', ctx.context, code=ATTR_DEFINED)
|
||||||
return AnyType(TypeOfAny.from_error)
|
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
|
assert str_info is not None
|
||||||
str_type = Instance(str_info, [])
|
str_type = Instance(str_info, [])
|
||||||
return analyze_member_access(
|
return analyze_member_access(
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class ModelClassInitializer:
|
|||||||
for method_name in MANAGER_METHODS_RETURNING_QUERYSET:
|
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))
|
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,
|
"any_fallback_manager": True,
|
||||||
"from_queryset_manager": fallback_queryset.fullname,
|
"from_queryset_manager": fallback_queryset.fullname,
|
||||||
}
|
}
|
||||||
@@ -521,7 +521,11 @@ class AddRelatedManagers(ModelClassInitializer):
|
|||||||
)
|
)
|
||||||
related_model_fullname = related_model_cls.__module__ + "." + related_model_cls.__name__
|
related_model_fullname = related_model_cls.__module__ + "." + related_model_cls.__name__
|
||||||
self.ctx.api.fail(
|
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,
|
self.ctx.cls,
|
||||||
code=MANAGER_MISSING,
|
code=MANAGER_MISSING,
|
||||||
)
|
)
|
||||||
@@ -539,8 +543,9 @@ class AddRelatedManagers(ModelClassInitializer):
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# The reverse manager we're looking for doesn't exist. So we create it.
|
# The reverse manager we're looking for doesn't exist. So we
|
||||||
# The (default) reverse manager type is built from a RelatedManager and the default manager on the related model
|
# 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, [])])
|
parametrized_related_manager_type = Instance(related_manager_info, [Instance(related_model_info, [])])
|
||||||
default_manager_type = default_manager.type
|
default_manager_type = default_manager.type
|
||||||
assert default_manager_type is not None
|
assert default_manager_type is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user