Repository navigation
Commit 0207097
committed
Raise on unexpected operands in the formula operators
The `match` in each binary operator covers all four combinations of its two
operands, plus the ones where an operand is `None`, and was followed by an
unreachable `return None`. mypy can't narrow tuple items across `case`
clauses (see python/mypy#12364), so it can't prove the `match` exhaustive no
matter how many cases are written.
Turn that trailing `return None` into the explicit last case, and raise
instead of returning, so an operand of an unexpected type fails early rather
than silently evaluating the whole formula to nothing: type hints are not
enforced at runtime. `assert_never()` can't be used here, as mypy doesn't
narrow the subject to `Never`.
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>1 parent 04cd32f commit 0207097
1 file changed
Lines changed: 20 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| |||
254 | 258 | | |
255 | 259 | | |
256 | 260 | | |
257 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
258 | 266 | | |
259 | 267 | | |
260 | 268 | | |
| |||
331 | 339 | | |
332 | 340 | | |
333 | 341 | | |
334 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
335 | 347 | | |
336 | 348 | | |
337 | 349 | | |
| |||
406 | 418 | | |
407 | 419 | | |
408 | 420 | | |
409 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
410 | 426 | | |
411 | 427 | | |
412 | 428 | | |
| |||
0 commit comments