Commit 877056e
committed
fix(policy): mypy narrowing for evaluator comparisons (homeassistant-ai#966)
`Predicate.value` is `Any | None` and `extract_path` returns `Any`, so
`val == pv`, `val > pv`, etc. inherit `Any` and trip the project's
`warn_return_any` mypy setting on functions declared `-> bool`. Wrap
the comparison branches in `bool(...)` to make the narrowing explicit.
Also guard the `regex` branch with `isinstance(pv, str)` so `re.search`
receives a definite `str` instead of `Any | None`; a non-string regex
value now returns False instead of raising TypeError at evaluation
time, which is the only sensible behavior for a malformed pattern.
No change to any test's expected outcome.1 parent 5ea9581 commit 877056e
1 file changed
Lines changed: 9 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | | - | |
| 60 | + | |
57 | 61 | | |
58 | | - | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
0 commit comments