Commit fe8a01e
committed
Centralize action-argument validation in modelapi
Route `Action.__init__` (in `structs.py`) through a single
`ActionList.validate_action` method (added to `utils.py`) so that direct
construction of `Action` instances applies the same schema check as the
parser. Previously the inline validation in `Action.__init__` had two
bugs:
- For positional actions (`no_setter_syntax` / `square_braces`,
e.g. `setConcentration`, `quit`, `saveConcentrations`) the
`arg_dict[type]` lookup returns an empty list `[]`, so the
`len(valid_arg_list) > 0` guard skipped validation entirely —
any args were accepted.
- For unknown action types the error message was good, but it ran
AFTER setting `self.type`, leaving a half-constructed object alive
in the rare case someone catches the exception.
The new `validate_action` adds:
- positional actions store args as a dict with `None` values
(the canonical shape the parser emits) — keyword-shape dicts
passed by hand are rejected with a clear error.
- per-action positional arity (`positional_arity` table) catches
`Action("quit", {'"x"': None})` (too many) and
`Action("setConcentration", {'"A()"': None})` (too few).
- normal-type validation: arg names must be in `arg_dict[type]`
(existing behavior, just centralized).
`Action.__init__` is simplified to call `validate_action` and then
just track duplicate-arg warnings in a small loop.
No behavior change for parse-time construction: the parser already
emits the canonical positional-args-as-`{value: None}` shape, so the
stricter direct-construction path doesn't reject anything the parser
produces.1 parent f571e3a commit fe8a01e
2 files changed
Lines changed: 96 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
461 | 482 | | |
462 | 483 | | |
463 | 484 | | |
464 | 485 | | |
465 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
466 | 556 | | |
467 | 557 | | |
468 | 558 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
| 305 | + | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
307 | 309 | | |
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
311 | 313 | | |
312 | | - | |
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
316 | | - | |
317 | | - | |
318 | | - | |
| 317 | + | |
319 | 318 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 319 | + | |
335 | 320 | | |
336 | 321 | | |
337 | 322 | | |
| |||
0 commit comments