Skip to content

Commit c366435

Browse files
authored
Use report_config_data mypy plugin hook to reset cache on changes (#1578)
1 parent 3caea3f commit c366435

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mypy_django_plugin/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,10 @@ def parse_ini_file(self, filepath: Path) -> None:
112112
self.strict_settings = parser.getboolean(section, "strict_settings", fallback=True)
113113
except ValueError:
114114
exit_with_error(INVALID_BOOL_SETTING.format(key="strict_settings"))
115+
116+
def to_json(self) -> Dict[str, Any]:
117+
"""We use this method to reset mypy cache via `report_config_data` hook."""
118+
return {
119+
"django_settings_module": self.django_settings_module,
120+
"strict_settings": self.strict_settings,
121+
}

mypy_django_plugin/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22
import sys
33
from functools import partial
4-
from typing import Callable, Dict, List, Optional, Tuple, Type
4+
from typing import Any, Callable, Dict, List, Optional, Tuple, Type
55

66
from mypy.modulefinder import mypy_path
77
from mypy.nodes import MypyFile, TypeInfo
@@ -14,6 +14,7 @@
1414
FunctionContext,
1515
MethodContext,
1616
Plugin,
17+
ReportConfigContext,
1718
)
1819
from mypy.types import Type as MypyType
1920

@@ -331,6 +332,10 @@ def get_dynamic_class_hook(self, fullname: str) -> Optional[Callable[[DynamicCla
331332
return create_new_manager_class_from_as_manager_method
332333
return None
333334

335+
def report_config_data(self, ctx: ReportConfigContext) -> Dict[str, Any]:
336+
# Cache would be cleared if any settings do change.
337+
return self.plugin_config.to_json()
338+
334339

335340
def plugin(version: str) -> Type[NewSemanalDjangoPlugin]:
336341
return NewSemanalDjangoPlugin

0 commit comments

Comments
 (0)