Applied idiomatic Python improvements and micro-optimizations across registries and API layer.
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 20s
CI / Tests (Python 3.13) (push) Successful in 19s
CI / Tests (Python 3.14) (push) Successful in 16s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 20s
CI / Tests (Python 3.13) (push) Successful in 19s
CI / Tests (Python 3.14) (push) Successful in 16s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
This commit is contained in:
@@ -48,7 +48,7 @@ def _make_user(
|
||||
user_id: str = "user-1",
|
||||
display_name: str = "Alice",
|
||||
is_authenticated: bool = False,
|
||||
scopes: list[str] | None = None,
|
||||
scopes: frozenset[str] | None = None,
|
||||
) -> User:
|
||||
"""Build a minimal User for test events."""
|
||||
return User(
|
||||
@@ -60,7 +60,7 @@ def _make_user(
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=is_authenticated,
|
||||
scopes=scopes or [],
|
||||
scopes=scopes or frozenset(),
|
||||
)
|
||||
|
||||
|
||||
@@ -657,7 +657,7 @@ class TestCommandDispatcherDispatch:
|
||||
dispatcher.register(
|
||||
"ban", handler, requires_moderator=True, module_name="mod_a"
|
||||
)
|
||||
user = _make_user(scopes=["MODERATOR"])
|
||||
user = _make_user(scopes=frozenset({"MODERATOR"}))
|
||||
await dispatcher.dispatch(_make_chat_event(body="!ban", user=user))
|
||||
|
||||
assert called is True
|
||||
@@ -676,7 +676,7 @@ class TestCommandDispatcherDispatch:
|
||||
dispatcher.register(
|
||||
"ping", handler, requires_moderator=True, module_name="mod_a"
|
||||
)
|
||||
user = _make_user(scopes=[])
|
||||
user = _make_user(scopes=frozenset())
|
||||
with caplog.at_level(logging.INFO, logger="owlbot.commands"):
|
||||
await dispatcher.dispatch(_make_chat_event(body="!ping", user=user))
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ class TestUser:
|
||||
assert user.name_changed_at == datetime(2025, 7, 1, 12, 0, tzinfo=UTC)
|
||||
assert user.is_bot is False
|
||||
assert user.is_authenticated is True
|
||||
assert user.scopes == ["MODERATOR"]
|
||||
assert user.scopes == frozenset({"MODERATOR"})
|
||||
|
||||
def test_empty_dict(self) -> None:
|
||||
"""An empty dict produces a User with all defaults."""
|
||||
@@ -218,7 +218,7 @@ class TestUser:
|
||||
assert user.name_changed_at is None
|
||||
assert user.is_bot is False
|
||||
assert user.is_authenticated is False
|
||||
assert user.scopes == []
|
||||
assert user.scopes == frozenset()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("scopes", "expected"),
|
||||
@@ -606,7 +606,7 @@ class TestLogEvent:
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=False,
|
||||
scopes=[],
|
||||
scopes=frozenset(),
|
||||
),
|
||||
client_id=1,
|
||||
body="Hello",
|
||||
@@ -630,7 +630,7 @@ class TestLogEvent:
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=False,
|
||||
scopes=[],
|
||||
scopes=frozenset(),
|
||||
),
|
||||
client_id=1,
|
||||
event_id="evt-001",
|
||||
@@ -651,7 +651,7 @@ class TestLogEvent:
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=False,
|
||||
scopes=[],
|
||||
scopes=frozenset(),
|
||||
),
|
||||
client_id=1,
|
||||
event_id="evt-002",
|
||||
@@ -672,7 +672,7 @@ class TestLogEvent:
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=False,
|
||||
scopes=[],
|
||||
scopes=frozenset(),
|
||||
),
|
||||
client_id=1,
|
||||
new_name="NewName",
|
||||
|
||||
@@ -63,7 +63,7 @@ def _make_user(
|
||||
name_changed_at=None,
|
||||
is_bot=False,
|
||||
is_authenticated=False,
|
||||
scopes=[],
|
||||
scopes=frozenset(),
|
||||
)
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ class TestEventRegistry:
|
||||
assert joined_entries[0].handler is handler
|
||||
|
||||
def test_register_multiple_handlers_same_type(self) -> None:
|
||||
"""Two handlers for the same type both appear in get()."""
|
||||
"""Two handlers for the same type both appear in get(), sorted by priority."""
|
||||
registry = EventRegistry()
|
||||
|
||||
async def handler_a(ctx: EventContext[Any]) -> None:
|
||||
@@ -243,8 +243,9 @@ class TestEventRegistry:
|
||||
registry.register(handler_b, (EventType.CHAT,), "mod_b", 75)
|
||||
entries = registry.get(EventType.CHAT)
|
||||
assert len(entries) == 2
|
||||
assert entries[0].handler is handler_a
|
||||
assert entries[1].handler is handler_b
|
||||
# Higher priority first (descending order).
|
||||
assert entries[0].handler is handler_b
|
||||
assert entries[1].handler is handler_a
|
||||
|
||||
def test_get_empty(self) -> None:
|
||||
"""get() on a fresh registry returns an empty list."""
|
||||
|
||||
Reference in New Issue
Block a user