rules: Fix last_result not passed among chained rules

A previous refactor accidentally broke chained rules that rely on the
result chaining, so fix it.

With it fixed, some rule examples from docs/rules.md work properly
again, yay!

    ---
    - Feature: THUMB WHEEL
    - Rule: [ Modifiers: Control, Test: thumb_wheel_up, MouseScroll: [-2, 0] ]
    - Rule:
      - Modifiers: Control
      - Test: thumb_wheel_down
      - MouseScroll: [-2, 0]
    - Rule: [ Or: [ Test: thumb_wheel_up, Test: thumb_wheel_down ], MouseScroll: [-1, 0] ]
    ...
    ---
    - Feature: LOWRES WHEEL
    - Rule: [ Or: [ Test: lowres_wheel_up, Test: lowres_wheel_down ], MouseScroll: [0, 2] ]
    ...

Fixes: 46366b2430 ("Fix warnings from automatic code inspections")
Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong 2026-06-18 00:25:19 +08:00
parent b56f30d24d
commit 94cb282c77
No known key found for this signature in database
GPG Key ID: 1C2D45D45AB7FE94
1 changed files with 5 additions and 6 deletions

View File

@ -481,14 +481,13 @@ class RuleComponent:
def _evaluate(components, feature, notification: HIDPPNotification, device, result) -> Any:
res = True
for component in components:
res = component.evaluate(feature, notification, device, result)
if not isinstance(component, Action) and res is None:
result = component.evaluate(feature, notification, device, result)
if not isinstance(component, Action) and result is None:
return None
if isinstance(component, Condition) and not res:
return res
return res
if isinstance(component, Condition) and not result:
return result
return result
class Rule(RuleComponent):