Skip to content

Commit

Permalink
chore: stricter mypy config
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans committed Dec 21, 2024
1 parent 7ddc048 commit a885a99
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
6 changes: 5 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions socnet/allauth/adapter.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion socnet/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions socnet/messenger/consumers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions tests/blog/factories.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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")

class Meta:
model = models.Post


class CommentFactory(DjangoModelFactory):
class CommentFactory(DjangoModelFactory[models.Comment]):
post = SubFactory(PostFactory)
author = SubFactory(UserFactory)
content = Faker("text")
Expand Down
8 changes: 7 additions & 1 deletion tests/blog/views/test_comment_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/users/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a885a99

Please sign in to comment.