|
3 | 3 | TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union, cast, |
4 | 4 | ) |
5 | 5 |
|
6 | | -from django.db.models.fields import Field |
7 | | -from django.db.models.fields.related import RelatedField |
8 | | -from django.db.models.fields.reverse_related import ForeignObjectRel |
9 | 6 | from mypy.checker import TypeChecker |
10 | 7 | from mypy.mro import calculate_mro |
11 | 8 | from mypy.nodes import ( |
@@ -121,22 +118,6 @@ def __call__(self, ctx: DynamicClassDefContext) -> None: |
121 | 118 | self.semanal_api = cast(SemanticAnalyzer, ctx.api) |
122 | 119 | self.create_new_dynamic_class() |
123 | 120 |
|
124 | | - def get_callee(self) -> MemberExpr: |
125 | | - callee = self.call_expr.callee |
126 | | - assert isinstance(callee, MemberExpr) |
127 | | - return callee |
128 | | - |
129 | | - def lookup_same_module_or_defer(self, name: str, *, |
130 | | - deferral_context: Optional[Context] = None) -> Optional[SymbolTableNode]: |
131 | | - sym = self.semanal_api.lookup_qualified(name, self.call_expr) |
132 | | - if sym is None or sym.node is None or isinstance(sym.node, PlaceholderNode): |
133 | | - deferral_context = deferral_context or self.call_expr |
134 | | - if not self.defer_till_next_iteration(deferral_context, |
135 | | - reason=f'{self.semanal_api.cur_mod_id}.{name} does not exist'): |
136 | | - raise new_helpers.NameNotFound(name) |
137 | | - return None |
138 | | - return sym |
139 | | - |
140 | 121 | @abstractmethod |
141 | 122 | def create_new_dynamic_class(self) -> None: |
142 | 123 | raise NotImplementedError |
@@ -343,21 +324,6 @@ def get_private_descriptor_type(type_info: TypeInfo, private_field_name: str, is |
343 | 324 | return AnyType(TypeOfAny.explicit) |
344 | 325 |
|
345 | 326 |
|
346 | | -def get_field_lookup_exact_type(api: AnyPluginAPI, field: Field) -> MypyType: |
347 | | - if isinstance(field, (RelatedField, ForeignObjectRel)): |
348 | | - lookup_type_class = field.related_model |
349 | | - rel_model_info = lookup_class_typeinfo(api, lookup_type_class) |
350 | | - if rel_model_info is None: |
351 | | - return AnyType(TypeOfAny.from_error) |
352 | | - return make_optional(Instance(rel_model_info, [])) |
353 | | - |
354 | | - field_info = lookup_class_typeinfo(api, field.__class__) |
355 | | - if field_info is None: |
356 | | - return AnyType(TypeOfAny.explicit) |
357 | | - return get_private_descriptor_type(field_info, '_pyi_lookup_exact_type', |
358 | | - is_nullable=field.null) |
359 | | - |
360 | | - |
361 | 327 | def get_current_module(api: AnyPluginAPI) -> MypyFile: |
362 | 328 | if isinstance(api, SemanticAnalyzer): |
363 | 329 | return api.cur_mod_node |
@@ -423,3 +389,10 @@ def new_typeinfo(name: str, |
423 | 389 |
|
424 | 390 | class_def.info = info |
425 | 391 | return info |
| 392 | + |
| 393 | + |
| 394 | +def get_nested_meta_node_for_current_class(info: TypeInfo) -> Optional[TypeInfo]: |
| 395 | + metaclass_sym = info.names.get('Meta') |
| 396 | + if metaclass_sym is not None and isinstance(metaclass_sym.node, TypeInfo): |
| 397 | + return metaclass_sym.node |
| 398 | + return None |
0 commit comments