mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 20:24:31 +08:00
remove dataclasses dependency
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple, Type
|
||||
|
||||
from django.core.exceptions import FieldError
|
||||
@@ -22,12 +21,6 @@ if TYPE_CHECKING:
|
||||
from django.conf import LazySettings
|
||||
|
||||
|
||||
@dataclass
|
||||
class DjangoPluginConfig:
|
||||
ignore_missing_settings: bool = False
|
||||
ignore_missing_model_attributes: bool = False
|
||||
|
||||
|
||||
@contextmanager
|
||||
def temp_environ():
|
||||
"""Allow the ability to set os.environ temporarily"""
|
||||
@@ -141,14 +134,11 @@ class DjangoLookupsContext:
|
||||
|
||||
class DjangoContext:
|
||||
def __init__(self, plugin_toml_config: Optional[Dict[str, Any]]) -> None:
|
||||
self.config = DjangoPluginConfig()
|
||||
self.fields_context = DjangoFieldsContext(self)
|
||||
self.lookups_context = DjangoLookupsContext(self)
|
||||
|
||||
self.django_settings_module = None
|
||||
if plugin_toml_config:
|
||||
self.config.ignore_missing_settings = plugin_toml_config.get('ignore_missing_settings', False)
|
||||
self.config.ignore_missing_model_attributes = plugin_toml_config.get('ignore_missing_model_attributes', False)
|
||||
self.django_settings_module = plugin_toml_config.get('django_settings_module', None)
|
||||
|
||||
self.apps_registry: Optional[Dict[str, str]] = None
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import dataclasses
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import cast
|
||||
|
||||
from django.db.models.fields.related import ForeignKey
|
||||
from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel, OneToOneRel
|
||||
from mypy.newsemanal.semanal import NewSemanticAnalyzer
|
||||
from mypy.nodes import ClassDef, MDEF, SymbolTableNode, TypeInfo, Var
|
||||
from mypy.nodes import MDEF, SymbolTableNode, TypeInfo, Var
|
||||
from mypy.plugin import ClassDefContext
|
||||
from mypy.types import Instance
|
||||
|
||||
@@ -15,19 +15,12 @@ from mypy_django_plugin.transformers import fields
|
||||
from mypy_django_plugin.transformers.fields import get_field_descriptor_types
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class ModelClassInitializer(metaclass=ABCMeta):
|
||||
api: NewSemanticAnalyzer
|
||||
model_classdef: ClassDef
|
||||
django_context: DjangoContext
|
||||
ctx: ClassDefContext
|
||||
|
||||
@classmethod
|
||||
def from_ctx(cls, ctx: ClassDefContext, django_context: DjangoContext):
|
||||
return cls(api=cast(NewSemanticAnalyzer, ctx.api),
|
||||
model_classdef=ctx.cls,
|
||||
django_context=django_context,
|
||||
ctx=ctx)
|
||||
def __init__(self, ctx: ClassDefContext, django_context: DjangoContext):
|
||||
self.api = cast(NewSemanticAnalyzer, ctx.api)
|
||||
self.model_classdef = ctx.cls
|
||||
self.django_context = django_context
|
||||
self.ctx = ctx
|
||||
|
||||
def lookup_typeinfo_or_incomplete_defn_error(self, fullname: str) -> TypeInfo:
|
||||
sym = self.api.lookup_fully_qualified_or_none(fullname)
|
||||
@@ -156,7 +149,7 @@ def process_model_class(ctx: ClassDefContext,
|
||||
]
|
||||
for initializer_cls in initializers:
|
||||
try:
|
||||
initializer_cls.from_ctx(ctx, django_context).run()
|
||||
initializer_cls(ctx, django_context).run()
|
||||
except helpers.IncompleteDefnException:
|
||||
if not ctx.api.final_iteration:
|
||||
ctx.api.defer()
|
||||
|
||||
Reference in New Issue
Block a user