|
5 | 5 | import toml |
6 | 6 | from mypy.nodes import MypyFile, TypeInfo |
7 | 7 | from mypy.options import Options |
8 | | -from mypy.plugin import ClassDefContext, FunctionContext, Plugin, MethodContext |
| 8 | +from mypy.plugin import ClassDefContext, FunctionContext, Plugin, MethodContext, AttributeContext |
9 | 9 | from mypy.types import Type as MypyType |
10 | 10 |
|
11 | 11 | from django.db.models.fields.related import RelatedField |
@@ -81,6 +81,10 @@ def _new_dependency(self, module: str) -> Tuple[int, str, int]: |
81 | 81 | return 10, module, -1 |
82 | 82 |
|
83 | 83 | def get_additional_deps(self, file: MypyFile) -> List[Tuple[int, str, int]]: |
| 84 | + # for settings |
| 85 | + if file.fullname() == 'django.conf' and self.django_context.django_settings_module: |
| 86 | + return [self._new_dependency(self.django_context.django_settings_module)] |
| 87 | + |
84 | 88 | # for `get_user_model()` |
85 | 89 | if file.fullname() == 'django.contrib.auth': |
86 | 90 | auth_user_model_name = self.django_context.settings.AUTH_USER_MODEL |
@@ -142,34 +146,12 @@ def get_base_class_hook(self, fullname: str |
142 | 146 | if fullname in self._get_current_manager_bases(): |
143 | 147 | return add_new_manager_base |
144 | 148 |
|
145 | | - # def get_attribute_hook(self, fullname: str |
146 | | - # ) -> Optional[Callable[[AttributeContext], MypyType]]: |
147 | | - # print(fullname) |
148 | | - # class_name, _, attr_name = fullname.rpartition('.') |
149 | | - # # if class_name == fullnames.DUMMY_SETTINGS_BASE_CLASS: |
150 | | - # # return partial(get_type_of_setting, |
151 | | - # # setting_name=attr_name, |
152 | | - # # settings_modules=self._get_settings_modules_in_order_of_priority(), |
153 | | - # # ignore_missing_settings=self.config.ignore_missing_settings) |
154 | | - # |
155 | | - # if class_name in self._get_current_model_bases(): |
156 | | - # # if attr_name == 'id': |
157 | | - # # return return_type_for_id_field |
158 | | - # |
159 | | - # model_info = self._get_typeinfo_or_none(class_name) |
160 | | - # if model_info: |
161 | | - # attr_sym = model_info.get(attr_name) |
162 | | - # if attr_sym and isinstance(attr_sym.node, TypeInfo) \ |
163 | | - # and helpers.has_any_of_bases(attr_sym.node, fullnames.MANAGER_CLASSES): |
164 | | - # return partial(querysets.determite_manager_type, django_context=self.django_context) |
165 | | - # |
166 | | - # # related_managers = metadata.get_related_managers_metadata(model_info) |
167 | | - # # if attr_name in related_managers: |
168 | | - # # return partial(determine_type_of_related_manager, |
169 | | - # # related_manager_name=attr_name) |
170 | | - # |
171 | | - # # if attr_name.endswith('_id'): |
172 | | - # # return extract_and_return_primary_key_of_bound_related_field_parameter |
| 149 | + def get_attribute_hook(self, fullname: str |
| 150 | + ) -> Optional[Callable[[AttributeContext], MypyType]]: |
| 151 | + class_name, _, attr_name = fullname.rpartition('.') |
| 152 | + if class_name == fullnames.DUMMY_SETTINGS_BASE_CLASS: |
| 153 | + return partial(settings.get_type_of_settings_attribute, |
| 154 | + django_context=self.django_context) |
173 | 155 |
|
174 | 156 | # def get_type_analyze_hook(self, fullname: str |
175 | 157 | # ) -> Optional[Callable[[AnalyzeTypeContext], MypyType]]: |
|
0 commit comments