lint fixes

This commit is contained in:
Maxim Kurnikov
2019-07-21 04:25:48 +03:00
parent 5b2aacddba
commit 4dfa363521
14 changed files with 59 additions and 49 deletions

View File

@@ -1,23 +1,26 @@
import os
from collections import defaultdict
from contextlib import contextmanager
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple, Type
from typing import (
TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Type,
)
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import FieldError
from django.db.models.base import Model
from django.db.models.fields import CharField, Field
from django.db.models.fields.related import ForeignKey, RelatedField
from django.db.models.fields.reverse_related import ForeignObjectRel
from django.db.models.sql.query import Query
from django.utils.functional import cached_property
from mypy.checker import TypeChecker
from mypy.types import Instance, Type as MypyType
from mypy.types import Instance
from mypy.types import Type as MypyType
from django.contrib.postgres.fields import ArrayField
from django.db.models.fields import CharField, Field
from mypy_django_plugin.lib import helpers
if TYPE_CHECKING:
from django.apps.registry import Apps
from django.apps.registry import Apps # noqa: F401
from django.conf import LazySettings

View File

@@ -1,13 +1,17 @@
from collections import OrderedDict
from typing import Any, Dict, List, Optional, Set, Union, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Union
from mypy import checker
from mypy.checker import TypeChecker
from mypy.mro import calculate_mro
from mypy.nodes import Block, ClassDef, Expression, GDEF, MDEF, MypyFile, NameExpr, StrExpr, SymbolNode, SymbolTable, \
SymbolTableNode, TypeInfo, Var, MemberExpr
from mypy.nodes import (
GDEF, MDEF, Block, ClassDef, Expression, MemberExpr, MypyFile, NameExpr, StrExpr, SymbolNode, SymbolTable,
SymbolTableNode, TypeInfo, Var,
)
from mypy.plugin import CheckerPluginInterface, FunctionContext, MethodContext
from mypy.types import AnyType, Instance, NoneTyp, TupleType, Type as MypyType, TypeOfAny, TypedDictType, UnionType
from mypy.types import AnyType, Instance, NoneTyp, TupleType
from mypy.types import Type as MypyType
from mypy.types import TypedDictType, TypeOfAny, UnionType
if TYPE_CHECKING:
from mypy_django_plugin.django.context import DjangoContext

View File

@@ -6,12 +6,16 @@ import toml
from django.db.models.fields.related import RelatedField
from mypy.nodes import MypyFile, TypeInfo
from mypy.options import Options
from mypy.plugin import AttributeContext, ClassDefContext, FunctionContext, MethodContext, Plugin
from mypy.plugin import (
AttributeContext, ClassDefContext, FunctionContext, MethodContext, Plugin,
)
from mypy.types import Type as MypyType
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.transformers import fields, forms, init_create, querysets, settings, meta, request
from mypy_django_plugin.transformers import (
fields, forms, init_create, meta, querysets, request, settings,
)
from mypy_django_plugin.transformers.models import process_model_class
@@ -109,7 +113,8 @@ class NewSemanalDjangoPlugin(Plugin):
# for `get_user_model()`
if self.django_context.settings:
if (file.fullname() == 'django.contrib.auth') or (file.fullname() in {'django.http', 'django.http.request'}):
if (file.fullname() == 'django.contrib.auth'
or file.fullname() in {'django.http', 'django.http.request'}):
auth_user_model_name = self.django_context.settings.AUTH_USER_MODEL
try:
auth_user_module = self.django_context.apps_registry.get_model(auth_user_model_name).__module__
@@ -208,7 +213,6 @@ class NewSemanalDjangoPlugin(Plugin):
if info and info.has_base(fullnames.HTTPREQUEST_CLASS_FULLNAME) and attr_name == 'user':
return partial(request.set_auth_user_model_as_type_for_request_user, django_context=self.django_context)
# def get_type_analyze_hook(self, fullname: str
# ( ):
# info = self._get_typeinfo_or_none(fullname)

View File

@@ -2,7 +2,9 @@ from typing import Optional, Tuple, cast
from mypy.nodes import MypyFile, TypeInfo
from mypy.plugin import FunctionContext
from mypy.types import AnyType, CallableType, Instance, Type as MypyType, TypeOfAny
from mypy.types import AnyType, CallableType, Instance
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers

View File

@@ -1,7 +1,9 @@
from typing import Optional
from mypy.plugin import ClassDefContext, MethodContext
from mypy.types import CallableType, Instance, NoneTyp, Type as MypyType, TypeType
from mypy.types import CallableType, Instance, NoneTyp
from mypy.types import Type as MypyType
from mypy.types import TypeType
from mypy_django_plugin.lib import helpers

View File

@@ -2,12 +2,14 @@ from typing import List, Tuple, Type, Union
from django.db.models.base import Model
from mypy.plugin import FunctionContext, MethodContext
from mypy.types import Instance, Type as MypyType
from mypy.types import Instance
from mypy.types import Type as MypyType
from mypy_django_plugin.django.context import DjangoContext
def get_actual_types(ctx: Union[MethodContext, FunctionContext], expected_keys: List[str]) -> List[Tuple[str, MypyType]]:
def get_actual_types(ctx: Union[MethodContext, FunctionContext],
expected_keys: List[str]) -> List[Tuple[str, MypyType]]:
actual_types = []
# positionals
for pos, (actual_name, actual_type) in enumerate(zip(ctx.arg_names[0], ctx.arg_types[0])):

View File

@@ -1,6 +1,8 @@
from django.core.exceptions import FieldDoesNotExist
from mypy.plugin import MethodContext
from mypy.types import AnyType, Type as MypyType, TypeOfAny, Instance
from mypy.types import AnyType, Instance
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers

View File

@@ -2,15 +2,19 @@ from collections import OrderedDict
from typing import Type, cast
from django.db.models.base import Model
from django.db.models.fields import DateField, DateTimeField
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.nodes import ARG_STAR2, Argument, MDEF, SymbolTableNode, TypeInfo, Var
from mypy.nodes import (
ARG_STAR2, MDEF, Argument, SymbolTableNode, TypeInfo, Var,
)
from mypy.plugin import ClassDefContext
from mypy.plugins import common
from mypy.types import AnyType, Instance, TypeOfAny
from django.db.models.fields import DateField, DateTimeField
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.transformers import fields

View File

@@ -1,12 +1,13 @@
from collections import OrderedDict
from typing import List, Optional, Sequence, Tuple, Type, Union, cast
from typing import List, Optional, Sequence, Tuple, Type, Union
from django.core.exceptions import FieldError
from django.db.models.base import Model
from mypy.checker import TypeChecker
from mypy.nodes import Expression, NameExpr
from mypy.plugin import AnalyzeTypeContext, FunctionContext, MethodContext
from mypy.types import AnyType, Instance, Type as MypyType, TypeOfAny
from mypy.types import AnyType, Instance
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers

View File

@@ -1,5 +1,6 @@
from mypy.plugin import AttributeContext
from mypy.types import Instance, Type as MypyType
from mypy.types import Instance
from mypy.types import Type as MypyType
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers

View File

@@ -1,6 +1,8 @@
from mypy.nodes import TypeInfo, MemberExpr
from mypy.plugin import FunctionContext, AttributeContext
from mypy.types import Type as MypyType, TypeType, Instance
from mypy.nodes import MemberExpr, TypeInfo
from mypy.plugin import AttributeContext, FunctionContext
from mypy.types import Instance
from mypy.types import Type as MypyType
from mypy.types import TypeType
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers
@@ -42,4 +44,3 @@ def get_type_of_settings_attribute(ctx: AttributeContext, django_context: Django
return ctx.default_attr_type
return Instance(value_info, [])

View File

@@ -1,5 +1,7 @@
# noinspection PyUnresolvedReferences
from pytest_mypy.collect import File, YamlTestFile, pytest_addoption
from pytest_mypy.collect import ( # noqa: F401
File, YamlTestFile, pytest_addoption,
)
from pytest_mypy.item import YamlTestItem
@@ -38,5 +40,3 @@ class NewSemanalDjangoTestItem(YamlTestItem):
mysettings_file = File(path='mysettings.py', content=settings_contents)
self.files.append(mysettings_file)

View File

@@ -1,31 +1,16 @@
import sys
from setuptools import setup
# with open('README.md', 'r') as f:
# readme = f.read()
dependencies = [
# 'pytest-mypy-plugins',
# 'mypy',
# 'decorator',
# 'capturer'
'pytest-mypy-plugins',
]
# if sys.version_info[:2] < (3, 7):
# # dataclasses port for 3.6
# dependencies += ['dataclasses']
setup(
name='pytest-django-stubs-newsemanal',
version='0.4.0',
# description='pytest plugin for writing tests for mypy plugins',
# long_description=readme,
# long_description_content_type='text/markdown',
license='MIT',
url="https://github.com/mkurnikov/pytest-mypy-plugins",
author="Maksim Kurnikov",
author_email="maxim.kurnikov@gmail.com",
# packages=['pytest_plugin'],
# the following makes a plugin available to pytest
entry_points={
'pytest11': [

View File

@@ -1,5 +1,4 @@
import os
import sys
from distutils.core import setup
from setuptools import find_packages