diff --git a/mypy_django_plugin/config.py b/mypy_django_plugin/config.py index de68c40cb..c4b00e7ae 100644 --- a/mypy_django_plugin/config.py +++ b/mypy_django_plugin/config.py @@ -112,3 +112,10 @@ def parse_ini_file(self, filepath: Path) -> None: self.strict_settings = parser.getboolean(section, "strict_settings", fallback=True) except ValueError: exit_with_error(INVALID_BOOL_SETTING.format(key="strict_settings")) + + def to_json(self) -> Dict[str, Any]: + """We use this method to reset mypy cache via `report_config_data` hook.""" + return { + "django_settings_module": self.django_settings_module, + "strict_settings": self.strict_settings, + } diff --git a/mypy_django_plugin/main.py b/mypy_django_plugin/main.py index ca7eadea2..af1a8e537 100644 --- a/mypy_django_plugin/main.py +++ b/mypy_django_plugin/main.py @@ -1,7 +1,7 @@ import itertools import sys from functools import partial -from typing import Callable, Dict, List, Optional, Tuple, Type +from typing import Any, Callable, Dict, List, Optional, Tuple, Type from mypy.modulefinder import mypy_path from mypy.nodes import MypyFile, TypeInfo @@ -14,6 +14,7 @@ FunctionContext, MethodContext, Plugin, + ReportConfigContext, ) from mypy.types import Type as MypyType @@ -331,6 +332,10 @@ def get_dynamic_class_hook(self, fullname: str) -> Optional[Callable[[DynamicCla return create_new_manager_class_from_as_manager_method return None + def report_config_data(self, ctx: ReportConfigContext) -> Dict[str, Any]: + # Cache would be cleared if any settings do change. + return self.plugin_config.to_json() + def plugin(version: str) -> Type[NewSemanalDjangoPlugin]: return NewSemanalDjangoPlugin