remove dataclasses dependency

This commit is contained in:
Maxim Kurnikov
2019-07-18 19:36:24 +03:00
parent 6ece759ca0
commit 07a9bcd4cb
3 changed files with 8 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
import os import os
from collections import defaultdict from collections import defaultdict
from contextlib import contextmanager from contextlib import contextmanager
from dataclasses import dataclass
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple, Type from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple, Type
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
@@ -22,12 +21,6 @@ if TYPE_CHECKING:
from django.conf import LazySettings from django.conf import LazySettings
@dataclass
class DjangoPluginConfig:
ignore_missing_settings: bool = False
ignore_missing_model_attributes: bool = False
@contextmanager @contextmanager
def temp_environ(): def temp_environ():
"""Allow the ability to set os.environ temporarily""" """Allow the ability to set os.environ temporarily"""
@@ -141,14 +134,11 @@ class DjangoLookupsContext:
class DjangoContext: class DjangoContext:
def __init__(self, plugin_toml_config: Optional[Dict[str, Any]]) -> None: def __init__(self, plugin_toml_config: Optional[Dict[str, Any]]) -> None:
self.config = DjangoPluginConfig()
self.fields_context = DjangoFieldsContext(self) self.fields_context = DjangoFieldsContext(self)
self.lookups_context = DjangoLookupsContext(self) self.lookups_context = DjangoLookupsContext(self)
self.django_settings_module = None self.django_settings_module = None
if plugin_toml_config: 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.django_settings_module = plugin_toml_config.get('django_settings_module', None)
self.apps_registry: Optional[Dict[str, str]] = None self.apps_registry: Optional[Dict[str, str]] = None

View File

@@ -1,11 +1,11 @@
import dataclasses from abc import ABCMeta, abstractmethod
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from typing import cast from typing import cast
from django.db.models.fields.related import ForeignKey from django.db.models.fields.related import ForeignKey
from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel, OneToOneRel from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel, OneToOneRel
from mypy.newsemanal.semanal import NewSemanticAnalyzer 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.plugin import ClassDefContext
from mypy.types import Instance 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 from mypy_django_plugin.transformers.fields import get_field_descriptor_types
@dataclasses.dataclass
class ModelClassInitializer(metaclass=ABCMeta): class ModelClassInitializer(metaclass=ABCMeta):
api: NewSemanticAnalyzer def __init__(self, ctx: ClassDefContext, django_context: DjangoContext):
model_classdef: ClassDef self.api = cast(NewSemanticAnalyzer, ctx.api)
django_context: DjangoContext self.model_classdef = ctx.cls
ctx: ClassDefContext self.django_context = django_context
self.ctx = ctx
@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 lookup_typeinfo_or_incomplete_defn_error(self, fullname: str) -> TypeInfo: def lookup_typeinfo_or_incomplete_defn_error(self, fullname: str) -> TypeInfo:
sym = self.api.lookup_fully_qualified_or_none(fullname) sym = self.api.lookup_fully_qualified_or_none(fullname)
@@ -156,7 +149,7 @@ def process_model_class(ctx: ClassDefContext,
] ]
for initializer_cls in initializers: for initializer_cls in initializers:
try: try:
initializer_cls.from_ctx(ctx, django_context).run() initializer_cls(ctx, django_context).run()
except helpers.IncompleteDefnException: except helpers.IncompleteDefnException:
if not ctx.api.final_iteration: if not ctx.api.final_iteration:
ctx.api.defer() ctx.api.defer()

View File

@@ -26,9 +26,6 @@ dependencies = [
'toml', 'toml',
'django' 'django'
] ]
if sys.version_info[:2] < (3, 7):
# dataclasses port for 3.6
dependencies += ['dataclasses']
setup( setup(
name="django-stubs", name="django-stubs",