From 93fa1d2e1965f26e98f59b42a11c9fda583de9bf Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 27 Sep 2022 11:55:36 +0300 Subject: [PATCH] Update mypy to 0.981 (#1167) * Update mypy to 0.981 * Fix plugin API * Fix scripts * Fix scripts * Fix plugin --- django-stubs/core/management/templates.pyi | 2 +- django-stubs/core/servers/basehttp.pyi | 2 +- django-stubs/db/models/base.pyi | 4 +++- django-stubs/db/models/query.pyi | 2 +- django-stubs/utils/feedgenerator.pyi | 2 +- mypy_django_plugin/transformers/managers.py | 2 +- mypy_django_plugin/transformers/models.py | 6 +++--- requirements.txt | 2 +- scripts/git_helpers.py | 2 +- scripts/typecheck_tests.py | 2 +- setup.py | 5 +++-- 11 files changed, 17 insertions(+), 14 deletions(-) diff --git a/django-stubs/core/management/templates.pyi b/django-stubs/core/management/templates.pyi index ea1ea28..d5fc135 100644 --- a/django-stubs/core/management/templates.pyi +++ b/django-stubs/core/management/templates.pyi @@ -11,7 +11,7 @@ class TemplateCommand(BaseCommand): paths_to_remove: Sequence[Any] verbosity: Any = ... def add_arguments(self, parser: ArgumentParser) -> None: ... - def handle(self, app_or_project: str, name: str, target: Optional[str] = ..., **options: Any) -> None: ... # type: ignore + def handle(self, app_or_project: str, name: str, target: Optional[str] = ..., **options: Any) -> None: ... def handle_template(self, template: Optional[str], subdir: Optional[str]) -> str: ... def validate_name(self, name: str, name_or_dir: str = ...) -> None: ... def download(self, url: str) -> str: ... diff --git a/django-stubs/core/servers/basehttp.pyi b/django-stubs/core/servers/basehttp.pyi index bef8ff8..15a0cae 100644 --- a/django-stubs/core/servers/basehttp.pyi +++ b/django-stubs/core/servers/basehttp.pyi @@ -20,7 +20,7 @@ class ServerHandler(simple_server.ServerHandler): class WSGIRequestHandler(simple_server.WSGIRequestHandler): close_connection: bool - connection: WSGIRequest # type: ignore[assignment] + connection: WSGIRequest request: WSGIRequest rfile: BytesIO wfile: BytesIO diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index fcb48a6..7104d80 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -36,7 +36,9 @@ class Model(metaclass=ModelBase): @classmethod def add_to_class(cls, name: str, value: Any): ... @classmethod - def from_db(cls, db: Optional[str], field_names: Collection[str], values: Collection[Any]) -> _Self: ... + def from_db( + cls: Type[_Self], db: Optional[str], field_names: Collection[str], values: Collection[Any] + ) -> _Self: ... def delete(self, using: Any = ..., keep_parents: bool = ...) -> Tuple[int, Dict[str, int]]: ... def full_clean(self, exclude: Optional[Iterable[str]] = ..., validate_unique: bool = ...) -> None: ... def clean(self) -> None: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 0bd830e..ec98170 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -133,7 +133,7 @@ class _QuerySet(Generic[_T, _Row], Collection[_Row], Reversible[_Row], Sized): def all(self: _QS) -> _QS: ... def filter(self: _QS, *args: Any, **kwargs: Any) -> _QS: ... def exclude(self: _QS, *args: Any, **kwargs: Any) -> _QS: ... - def complex_filter(self, filter_obj: Any) -> _QS: ... + def complex_filter(self: _QS, filter_obj: Any) -> _QS: ... def count(self) -> int: ... async def acount(self) -> int: ... def union(self: _QS, *other_qs: Any, all: bool = ...) -> _QS: ... diff --git a/django-stubs/utils/feedgenerator.pyi b/django-stubs/utils/feedgenerator.pyi index ba42f1f..f1f0249 100644 --- a/django-stubs/utils/feedgenerator.pyi +++ b/django-stubs/utils/feedgenerator.pyi @@ -1,6 +1,6 @@ import datetime from typing import Any, Dict, List, Optional, Tuple, Union -from xml.sax import ContentHandler # type: ignore +from xml.sax import ContentHandler def rfc2822_date(date: datetime.date) -> str: ... def rfc3339_date(date: datetime.date) -> str: ... diff --git a/mypy_django_plugin/transformers/managers.py b/mypy_django_plugin/transformers/managers.py index 560ebbf..39ee933 100644 --- a/mypy_django_plugin/transformers/managers.py +++ b/mypy_django_plugin/transformers/managers.py @@ -16,7 +16,7 @@ from mypy.nodes import ( Var, ) from mypy.plugin import AttributeContext, DynamicClassDefContext, SemanticAnalyzerPluginInterface -from mypy.semanal import has_placeholder +from mypy.semanal_shared import has_placeholder from mypy.types import AnyType, CallableType, Instance, ProperType from mypy.types import Type as MypyType from mypy.types import TypeOfAny diff --git a/mypy_django_plugin/transformers/models.py b/mypy_django_plugin/transformers/models.py index f236abf..e6d3250 100644 --- a/mypy_django_plugin/transformers/models.py +++ b/mypy_django_plugin/transformers/models.py @@ -11,7 +11,7 @@ from mypy.plugins import common from mypy.semanal import SemanticAnalyzer from mypy.types import AnyType, Instance from mypy.types import Type as MypyType -from mypy.types import TypedDictType, TypeOfAny +from mypy.types import TypedDictType, TypeOfAny, get_proper_type from mypy.typevars import fill_typevars from mypy_django_plugin.django.context import DjangoContext @@ -656,11 +656,11 @@ def handle_annotated_type(ctx: AnalyzeTypeContext, django_context: DjangoContext fields_dict = None if len(args) > 1: - second_arg_type = ctx.api.analyze_type(args[1]) + second_arg_type = get_proper_type(ctx.api.analyze_type(args[1])) if isinstance(second_arg_type, TypedDictType): fields_dict = second_arg_type elif isinstance(second_arg_type, Instance) and second_arg_type.type.fullname == ANNOTATIONS_FULLNAME: - annotations_type_arg = second_arg_type.args[0] + annotations_type_arg = get_proper_type(second_arg_type.args[0]) if isinstance(annotations_type_arg, TypedDictType): fields_dict = annotations_type_arg elif not isinstance(annotations_type_arg, AnyType): diff --git a/requirements.txt b/requirements.txt index a6db709..cab9c02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,4 @@ psycopg2-binary -e .[compatible-mypy] # Overrides: -mypy==0.971 +mypy==0.981 diff --git a/scripts/git_helpers.py b/scripts/git_helpers.py index 14a63ea..cc7a0f9 100644 --- a/scripts/git_helpers.py +++ b/scripts/git_helpers.py @@ -17,7 +17,7 @@ class ProgressPrinter(RemoteProgress): print(self._cur_line) -def checkout_django_branch(django_version: str, commit_sha: Optional[str]) -> Repo: +def checkout_django_branch(django_version: str, commit_sha: Optional[str]) -> None: branch = f"stable/{django_version}.x" if DJANGO_SOURCE_DIRECTORY.exists(): shutil.rmtree(DJANGO_SOURCE_DIRECTORY) diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index 7b0313a..982af00 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -68,7 +68,7 @@ if __name__ == "__main__": django_version = parser.parse_args().django_version subprocess.check_call([sys.executable, "-m", "pip", "install", f"Django=={django_version}.*"]) commit_sha = DJANGO_COMMIT_REFS[django_version] - repo = checkout_django_branch(django_version, commit_sha) + checkout_django_branch(django_version, commit_sha) mypy_config_file = (PROJECT_DIRECTORY / "mypy.ini").absolute() mypy_cache_dir = PROJECT_DIRECTORY / ".mypy_cache" tests_root = DJANGO_SOURCE_DIRECTORY / "tests" diff --git a/setup.py b/setup.py index eef4e77..2891ef4 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ with open("README.md") as f: readme = f.read() dependencies = [ - "mypy>=0.930", + "mypy>=0.980", "django", "django-stubs-ext>=0.6.0", "tomli", @@ -31,7 +31,7 @@ dependencies = [ ] extras_require = { - "compatible-mypy": ["mypy>=0.930,<0.980"], + "compatible-mypy": ["mypy>=0.980,<0.990"], } setup( @@ -69,6 +69,7 @@ setup( "Framework :: Django :: 3.1", "Framework :: Django :: 3.2", "Framework :: Django :: 4.0", + "Framework :: Django :: 4.1", ], project_urls={ "Release notes": "https://github.com/typeddjango/django-stubs/releases",