From 88f5edcf2c7fb2952c63d36c99922878f0032631 Mon Sep 17 00:00:00 2001 From: Fruktus Date: Tue, 4 Aug 2026 17:29:21 +0200 Subject: [PATCH] chore: add missing types for message class utils Adds missing type annotations for message class utils responsible for building the list of all supported message classes to satisfy mypy --- server/src/QRServer/common/messages.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/src/QRServer/common/messages.py b/server/src/QRServer/common/messages.py index 58397397..749814fa 100644 --- a/server/src/QRServer/common/messages.py +++ b/server/src/QRServer/common/messages.py @@ -1,7 +1,7 @@ import inspect import sys from datetime import datetime, timezone -from typing import Sequence, Type +from typing import Any, Sequence, Type, TypeGuard from QRServer.common import powers from QRServer.common.classes import GameResultHistory, MatchStats, RankingEntry, LobbyPlayer @@ -972,9 +972,18 @@ def new(cls): # UTILS ################################################################################ -__message_classes_full = inspect.getmembers( +def is_message_class(obj: Any) -> TypeGuard[type[Message]]: + return ( + inspect.isclass(obj) + and issubclass(obj, Message) + and obj.__module__ == __name__ + and obj.prefix is not None + ) + + +__message_classes_full: list[tuple[str, type[Message]]] = inspect.getmembers( sys.modules[__name__], - lambda o: inspect.isclass(o) and o.__module__ == __name__ and o.prefix, + is_message_class, ) __message_classes: list[Type[Message]] = list(map(lambda member: member[1], __message_classes_full))