Commit a373eb2
refactor(registry): populate _module_meta in register/register_internal too
Cross-repo alignment with apcore-typescript: make python's manual
register() and register_internal() entry points populate _module_meta
via merge_module_metadata, just like _register_in_order (the discovery
path). After this change every registered module — discovery, manual,
internal — has a fully merged metadata dict in _module_meta, so
get_definition() can read uniformly from `meta` without fallback.
Changes:
- Registry.register() — pre-compute merge_module_metadata(module, metadata or {})
outside the lock, store under the lock alongside _modules /
_lowercase_map, and pop on on_load() rollback.
- Registry.register_internal() — same pre-compute + store, with
meta={} since the privileged sys-module path supplies no YAML.
- Registry._register_in_order() — pass the instance (not the class)
to merge_module_metadata, matching the new uniform contract. The
instance picks up __init__-set attributes, and getattr falls
through to class attrs anyway, so this is a strict superset of
the prior class-only pass.
- get_definition() — drop the `if "annotations" in meta else
getattr(module, ...)` fallback chain. With the invariant above,
meta always has all canonical keys, so reads collapse to plain
meta.get(...) calls. Mirrors apcore-typescript Registry.getDefinition
after its 64491b7 cleanup.
merge_module_metadata robustness fixes (uncovered by the test suite
when this change widened the set of inputs reaching it):
- Add _coerce_code_annotations helper that narrows the raw
`module.annotations` attribute to ModuleAnnotations | None. Real
ModuleAnnotations instances pass through; dict-style annotations
get filtered to canonical fields and re-constructed; everything
else (None, MagicMock test stubs, custom objects) becomes None
instead of crashing merge_annotations downstream.
- Defensive isinstance() guards on every code-side fallback so a
test stub returning a MagicMock for `description`/`name`/`tags`/
`version`/`metadata`/`documentation` does not propagate through
the merged dict.
- Accept either an instance or a class as the first parameter
(renamed from `module_class` to `module` to reflect this).
Tests: pytest 2252 pass / 2 xfail. pyright clean. ruff + black clean.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 106ee7f commit a373eb2
2 files changed
Lines changed: 89 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
68 | 90 | | |
69 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
70 | 98 | | |
71 | 99 | | |
72 | 100 | | |
73 | 101 | | |
74 | 102 | | |
75 | 103 | | |
76 | 104 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
85 | 113 | | |
86 | 114 | | |
87 | 115 | | |
88 | 116 | | |
89 | 117 | | |
90 | | - | |
| 118 | + | |
91 | 119 | | |
92 | 120 | | |
93 | 121 | | |
94 | 122 | | |
95 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
96 | 128 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
101 | 135 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
105 | 139 | | |
106 | 140 | | |
107 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
| |||
539 | 542 | | |
540 | 543 | | |
541 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
542 | 556 | | |
543 | 557 | | |
544 | 558 | | |
| |||
568 | 582 | | |
569 | 583 | | |
570 | 584 | | |
| 585 | + | |
571 | 586 | | |
572 | 587 | | |
573 | 588 | | |
| |||
580 | 595 | | |
581 | 596 | | |
582 | 597 | | |
| 598 | + | |
583 | 599 | | |
584 | 600 | | |
585 | 601 | | |
| |||
728 | 744 | | |
729 | 745 | | |
730 | 746 | | |
731 | | - | |
732 | | - | |
733 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
734 | 754 | | |
735 | 755 | | |
736 | | - | |
737 | | - | |
738 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
739 | 759 | | |
740 | 760 | | |
741 | | - | |
742 | | - | |
743 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
744 | 764 | | |
745 | 765 | | |
746 | 766 | | |
| |||
1127 | 1147 | | |
1128 | 1148 | | |
1129 | 1149 | | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
1130 | 1157 | | |
1131 | 1158 | | |
1132 | 1159 | | |
1133 | 1160 | | |
1134 | 1161 | | |
1135 | 1162 | | |
1136 | 1163 | | |
| 1164 | + | |
1137 | 1165 | | |
1138 | 1166 | | |
1139 | 1167 | | |
| |||
0 commit comments