Skip to content

Type Game.status as GameStatus instead of str#248

Merged
zarvox32 merged 1 commit into
mainfrom
zarvox/fix-game-status-type
May 16, 2026
Merged

Type Game.status as GameStatus instead of str#248
zarvox32 merged 1 commit into
mainfrom
zarvox/fix-game-status-type

Conversation

@zarvox32
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #226 (review comment item 2). The field was left as
status: str = GameStatus.WAITING — declared str, assigned enum.
Mashumaro looks at the declared type to (de)serialize, so a round-trip
would silently downcast the field to a plain str.

This PR changes the field and the GameProtocol declaration to
status: GameStatus. Equality comparisons against raw strings (the
existing pattern across game files) keep working via GameStatus(str, Enum)'s
str inheritance.

Test plan

  • Probed PigGame.to_dict() → from_dict() round-trip: before this
    change the deserialized field was str('playing'); after, it is
    GameStatus.PLAYING.
  • pytest tests/test_event_handling_mixin.py tests/test_game_communication_mixin.py tests/test_pig.py tests/test_table_manager.py tests/test_keybinds.py tests/test_database.py tests/test_integration.py tests/test_server_tables_menus.py — 94 passed.
  • cli.py simulate pig --bots 2 --test-serialization completes.

🤖 Generated with Claude Code

After #226, the field was declared `status: str = GameStatus.WAITING`
— declared str, assigned enum. Mashumaro inspects the declared type
when (de)serializing, so a round-trip would discard the enum and leave
a plain str on the field. Verified by a quick PigGame.to_dict /
from_dict probe before this change: deserialized as `str('playing')`;
after this change: deserialized as `GameStatus.PLAYING`.

Equality comparisons against raw strings continue to work because
GameStatus inherits from str. The GameProtocol declaration is updated
in lockstep.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@zarvox32 zarvox32 merged commit 6e2e41c into main May 16, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant