From 4f9999efa5d14bbe8dcb16ad55d636563d553bae Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 7 Feb 2026 22:10:30 -0500 Subject: [PATCH] Add PlayerData TypedDict to fix type errors --- src/mudlib/server.py | 3 ++- src/mudlib/store/__init__.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/mudlib/server.py b/src/mudlib/server.py index f66540e..e5c4fa2 100644 --- a/src/mudlib/server.py +++ b/src/mudlib/server.py @@ -21,6 +21,7 @@ from mudlib.content import load_commands from mudlib.effects import clear_expired from mudlib.player import Player, players from mudlib.store import ( + PlayerData, account_exists, authenticate, create_account, @@ -229,7 +230,7 @@ async def shell( update_last_login(player_name) # Load player data from database or use defaults for new player - player_data = login_result["player_data"] + player_data: PlayerData | None = login_result["player_data"] if player_data is None: # New player - find a passable starting position center_x = _world.width // 2 diff --git a/src/mudlib/store/__init__.py b/src/mudlib/store/__init__.py index 1f249cb..213487c 100644 --- a/src/mudlib/store/__init__.py +++ b/src/mudlib/store/__init__.py @@ -5,9 +5,22 @@ import hmac import os import sqlite3 from pathlib import Path +from typing import TypedDict from mudlib.player import Player + +class PlayerData(TypedDict): + """Shape of persisted player data from the database.""" + + x: int + y: int + pl: float + stamina: float + max_stamina: float + flying: bool + + # Module-level database path _db_path: str | None = None @@ -188,7 +201,7 @@ def save_player(player: Player) -> None: conn.close() -def load_player_data(name: str) -> dict | None: +def load_player_data(name: str) -> PlayerData | None: """Load player data from the database. Args: