diff --git a/mypy.ini b/mypy.ini index c1b6db4c..9787cef0 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,11 +1,14 @@ [mypy] +follow_untyped_imports = True python_version = 3.13 disallow_subclassing_any = False +disallow_untyped_calls = False disallow_untyped_decorators = False warn_unreachable = True local_partial_types = True enable_error_code = redundant-self, + deprecated, redundant-expr, possibly-undefined, truthy-bool, @@ -20,7 +23,8 @@ plugins = mypy_django_plugin.main, mypy_drf_plugin.main -[mypy-allauth.*,channels.*,channels_redis.*,debug_toolbar.*,django_filters.*,environ.*,factory.*] +[mypy-factory.django.*] +follow_untyped_imports = False ignore_missing_imports = True [mypy.plugins.django-stubs] diff --git a/socnet/allauth/adapter.py b/socnet/allauth/adapter.py index c0066824..af1bd00c 100644 --- a/socnet/allauth/adapter.py +++ b/socnet/allauth/adapter.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, override from allauth.account.adapter import DefaultAccountAdapter from allauth.account.utils import user_field @@ -13,12 +13,13 @@ class AccountAdapter(DefaultAccountAdapter): + @override def save_user( self, request: HttpRequest, user: User, form: SignupForm, - commit: bool = True, # noqa: FBT001, FBT002 + commit: bool = True, ) -> User: user = super().save_user(request, user, form, commit=False) user_field(user, "display_name", form.cleaned_data["display_name"]) diff --git a/socnet/api/filters.py b/socnet/api/filters.py index ae9f4f18..693fb66a 100644 --- a/socnet/api/filters.py +++ b/socnet/api/filters.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models -from django_filters import FilterSet +from django_filters.filterset import FilterSet if TYPE_CHECKING: from collections.abc import Iterator diff --git a/socnet/messenger/consumers.py b/socnet/messenger/consumers.py index cc624707..75f840bb 100644 --- a/socnet/messenger/consumers.py +++ b/socnet/messenger/consumers.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, override from channels.db import database_sync_to_async from channels.generic.websocket import AsyncJsonWebsocketConsumer @@ -41,6 +41,7 @@ def save_obj(obj: Model) -> None: class ChatConsumer(AsyncJsonWebsocketConsumer): channel_layer: RedisChannelLayer | InMemoryChannelLayer + @override async def connect(self) -> None: user: User | AnonymousUser = self.scope["user"] if user.is_anonymous: @@ -55,15 +56,15 @@ async def connect(self) -> None: await self.channel_layer.group_add(self.group, self.channel_name) await self.accept() - async def disconnect(self, code: int) -> None: # noqa: ARG002 + @override + async def disconnect(self, code: int) -> None: if not hasattr(self, "group"): return await self.channel_layer.group_discard(self.group, self.channel_name) + @override async def receive_json( - self, - content: dict[str, str], - **kwargs: Any, # noqa: ARG002 + self, content: dict[str, str], **kwargs: Any ) -> None: sender: User = self.scope["user"] message = models.Message( diff --git a/tests/blog/factories.py b/tests/blog/factories.py index 70736f8a..64bbcf80 100644 --- a/tests/blog/factories.py +++ b/tests/blog/factories.py @@ -1,13 +1,14 @@ from __future__ import annotations -from factory import Faker, SubFactory +from factory.declarations import SubFactory from factory.django import DjangoModelFactory +from factory.faker import Faker from socnet.blog import models from tests.users.factories import UserFactory -class PostFactory(DjangoModelFactory): +class PostFactory(DjangoModelFactory[models.Post]): author = SubFactory(UserFactory) content = Faker("text") @@ -15,7 +16,7 @@ class Meta: model = models.Post -class CommentFactory(DjangoModelFactory): +class CommentFactory(DjangoModelFactory[models.Comment]): post = SubFactory(PostFactory) author = SubFactory(UserFactory) content = Faker("text") diff --git a/tests/blog/views/test_comment_update.py b/tests/blog/views/test_comment_update.py index 658817c0..a15925e9 100644 --- a/tests/blog/views/test_comment_update.py +++ b/tests/blog/views/test_comment_update.py @@ -77,7 +77,13 @@ def test_author_post(client: Client) -> None: assert response.redirect_chain == [ ( "{}#comment{}".format( - reverse("blog:post", args=(comment.post.pk,)), comment.pk + reverse( + "blog:post", + args=( + comment.post.pk, # type: ignore[attr-defined] + ), + ), + comment.pk, ), 302, ) diff --git a/tests/users/factories.py b/tests/users/factories.py index 64e77caf..97ae49da 100644 --- a/tests/users/factories.py +++ b/tests/users/factories.py @@ -2,8 +2,8 @@ from typing import TYPE_CHECKING -from factory import Faker from factory.django import DjangoModelFactory, Password +from factory.faker import Faker from socnet.users.models import User