mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 12:44:29 +08:00
fix mypy errors
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from typing import cast
|
||||
|
||||
from mypy.checker import TypeChecker
|
||||
from mypy.nodes import MemberExpr, TypeInfo
|
||||
from mypy.plugin import AttributeContext, FunctionContext
|
||||
from mypy.types import Instance
|
||||
@@ -13,7 +16,8 @@ def get_user_model_hook(ctx: FunctionContext, django_context: DjangoContext) ->
|
||||
model_cls = django_context.apps_registry.get_model(auth_user_model)
|
||||
model_cls_fullname = helpers.get_class_fullname(model_cls)
|
||||
|
||||
model_info = helpers.lookup_fully_qualified_generic(model_cls_fullname, ctx.api.modules)
|
||||
model_info = helpers.lookup_fully_qualified_generic(model_cls_fullname,
|
||||
helpers.get_typechecker_api(ctx).modules)
|
||||
assert isinstance(model_info, TypeInfo)
|
||||
|
||||
return TypeType(Instance(model_info, []))
|
||||
@@ -26,9 +30,11 @@ def get_type_of_settings_attribute(ctx: AttributeContext, django_context: Django
|
||||
ctx.api.fail(f"'Settings' object has no attribute {setting_name!r}", ctx.context)
|
||||
return ctx.default_attr_type
|
||||
|
||||
typechecker_api = helpers.get_typechecker_api(ctx)
|
||||
|
||||
# first look for the setting in the project settings file, then global settings
|
||||
settings_module = ctx.api.modules.get(django_context.django_settings_module)
|
||||
global_settings_module = ctx.api.modules.get('django.conf.global_settings')
|
||||
settings_module = typechecker_api.modules.get(django_context.django_settings_module)
|
||||
global_settings_module = typechecker_api.modules.get('django.conf.global_settings')
|
||||
for module in [settings_module, global_settings_module]:
|
||||
if module is not None:
|
||||
sym = module.names.get(setting_name)
|
||||
@@ -39,7 +45,7 @@ def get_type_of_settings_attribute(ctx: AttributeContext, django_context: Django
|
||||
value = getattr(django_context.settings, setting_name)
|
||||
value_fullname = helpers.get_class_fullname(value.__class__)
|
||||
|
||||
value_info = helpers.lookup_fully_qualified_typeinfo(ctx.api, value_fullname)
|
||||
value_info = helpers.lookup_fully_qualified_typeinfo(typechecker_api, value_fullname)
|
||||
if value_info is None:
|
||||
return ctx.default_attr_type
|
||||
|
||||
|
||||
Reference in New Issue
Block a user