Skip to content

Commit

Permalink
Fix type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
Era-Dorta committed Oct 7, 2024
1 parent c50fc47 commit 4b8d8a0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ line-length = 120
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN", # Annotations
"D", # Docstrings
"FIX", # TODO, FIXME and other messages
"ERA001", # Commented out code
Expand Down
7 changes: 4 additions & 3 deletions src/signalblast/commands_strings.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import inspect
import re
from collections.abc import Iterator
from dataclasses import dataclass


class _IterableDataClass:
_public_attr = None

@classmethod
def _get_public_attributes(cls):
cls._public_attr = []
def _get_public_attributes(cls) -> None:
cls._public_attr: list[str] = []
for attr, value in inspect.getmembers(cls):
if not (attr.startswith("_") or inspect.ismethod(value)):
cls._public_attr.append(value)

def __iter__(self):
def __iter__(self) -> Iterator[str]:
if self._public_attr is None:
self._get_public_attributes()

Expand Down
6 changes: 3 additions & 3 deletions src/signalblast/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def empty_list_to_none(self, attachments: list[str] | None) -> list | None:

return attachments

def delete_attachments(self, attachments: list[str] | None, link_previews: list[str] | None):
def delete_attachments(self, attachments: list[str] | None, link_previews: list[str] | None) -> None:
if attachments is not None:
for attachment in attachments:
(self.attachments_folder / attachment).unlink()
Expand All @@ -34,12 +34,12 @@ def delete_attachments(self, attachments: list[str] | None, link_previews: list[

@staticmethod
def _compose_help_message(*, add_admin_commands: bool) -> str:
def _add_commands(message):
def _add_commands(message: str) -> str:
for command_str in PublicCommandStrings:
message += "\t" + command_str + "\n"
return message

def _add_admin_commands(message):
def _add_admin_commands(message: str) -> str:
for command_str, command_arg in zip(AdminCommandStrings, AdminCommandArgs, strict=False):
message += "\t" + command_str + " " + command_arg + "\n"
return message
Expand Down
9 changes: 5 additions & 4 deletions src/signalblast/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path


Expand All @@ -23,7 +24,7 @@ async def remove(self, uuid: str) -> None:
del self.data[uuid]
await self.save_to_file()

async def save_to_file(self):
async def save_to_file(self) -> None:
with self.save_path.open("w") as f:
csv_writer = csv.DictWriter(f, fieldnames=[self._uuid_str, self._phone_number_str])
csv_writer.writeheader()
Expand All @@ -42,13 +43,13 @@ async def _load_from_file(save_path: Path) -> Users:
def get_phone_number(self, uuid: str) -> str | None:
return self.data.get(uuid)

def __iter__(self):
def __iter__(self) -> Iterator[str | None]:
yield from self.data

def __contains__(self, uuid: str):
def __contains__(self, uuid: str) -> bool:
return uuid in self.data

def __len__(self):
def __len__(self) -> int:
return len(self.data)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion src/signalblast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_code_data_path() -> Path:
def triggered(pattern: Pattern) -> Callable:
def decorator_triggered(func: Callable) -> Callable:
@functools.wraps(func)
async def wrapper_triggered(*args, **kwargs):
async def wrapper_triggered(*args, **kwargs) -> Callable: # noqa: ANN002, ANN003
c: ChatContext = args[1]
text = c.message.text
if not isinstance(text, str):
Expand Down

0 comments on commit 4b8d8a0

Please sign in to comment.