Add dynamic dataclass and class attribute resolvers

Introduced `dataclass_kwargs` to ensure compatibility with different Python versions and modular attribute handling. Added utilities for resolving class attributes dynamically, enhancing flexibility with MRO-based resolvers. Updated tests to verify new features and ensure proper functionality across various scenarios.
This commit is contained in:
JRoot Junior 2025-03-01 18:22:41 +02:00
parent d36a10d428
commit b146b7aa85
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
7 changed files with 349 additions and 13 deletions

View file

@ -1708,3 +1708,45 @@ class TestSceneHandlersOrdering:
assert collect_handler_names(Scene1) == ["handler1", "handler2"]
assert collect_handler_names(Scene2) == ["handler2", "handler1"]
def test_inherited_handlers_follow_mro_order(self):
class Scene1(Scene):
@on.message()
async def handler1(self, message: Message) -> None:
pass
@on.message()
async def handler2(self, message: Message) -> None:
pass
class Scene2(Scene1):
@on.message()
async def handler3(self, message: Message) -> None:
pass
@on.message()
async def handler4(self, message: Message) -> None:
pass
assert collect_handler_names(Scene2) == ["handler3", "handler4", "handler1", "handler2"]
def test_inherited_overwrite_follow_mro_order(self):
class Scene1(Scene):
@on.message()
async def handler1(self, message: Message) -> None:
pass
@on.message()
async def handler2(self, message: Message) -> None:
pass
class Scene2(Scene1):
@on.message()
async def handler2(self, message: Message) -> None:
pass
@on.message()
async def handler3(self, message: Message) -> None:
pass
assert collect_handler_names(Scene2) == ["handler3", "handler1", "handler2"]