Skip to content

refactor(actor)!: Resolve and cache handlers by message type - #953

Merged
gfieni merged 2 commits into
masterfrom
refactor/state-handler-lookup
Oct 15, 2026
Merged

gfieni merged 2 commits into
masterfrom
refactor/state-handler-lookup

Conversation

@gfieni

@gfieni gfieni commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

PR overview:

  • Resolve handlers through the message class’s MRO, giving specific handlers precedence over catch-all handlers regardless of registration order.
  • Cache successful resolutions by message class and clear the cache on every registration.
  • Support later-loaded and deeper subclasses, and prevent collisions between unrelated message classes sharing a name.
  • Move State related tests into test_state.py.

Breaking changes:

  • Remove include_subclasses from State.add_handler(); inheritance matching is now unconditional.
  • Use class objects instead of class names as keys in State.handlers.
  • Rename State.dispatch_message() to State.handle_message().

Resolve handlers through the message class’s MRO, giving specific
handlers precedence over catch-all handlers regardless of registration
order. Support later-loaded and deeper subclasses, and use class keys to
avoid name collisions. Cache successful resolutions and clear the cache
on every registration.

BREAKING CHANGE: Remove `include_subclasses` argument to
`State.add_handler` method.  Inheritance matching is unconditional.
`State.handlers` now uses class objects instead of class names as keys.
@gfieni gfieni self-assigned this Oct 15, 2026
@gfieni
gfieni requested a review from a team as a code owner October 15, 2026 13:12
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.77%. Comparing base (dbbd07d) to head (269fa3b).

Files with missing lines Patch % Lines
src/powerapi/actor/actor.py 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #953      +/-   ##
==========================================
+ Coverage   86.72%   86.77%   +0.04%     
==========================================
  Files          81       81              
  Lines        2817     2827      +10     
==========================================
+ Hits         2443     2453      +10     
  Misses        374      374              
Files with missing lines Coverage Δ
src/powerapi/actor/handler.py 83.33% <100.00%> (ø)
src/powerapi/actor/state.py 92.10% <100.00%> (+2.81%) ⬆️
src/powerapi/actor/actor.py 75.82% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gfieni
gfieni merged commit 144e8eb into master Oct 15, 2026
10 checks passed
@gfieni
gfieni deleted the refactor/state-handler-lookup branch October 15, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant