Repository navigation
Conversation
…oved Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
… refmode PR 3 of devnotes/ToolAPIDesign.md: T5's ReferenceProxy members and F2. Resolved slots (decision 7) are the next stage; until then a slot of an ItemSpace still holds the item's copy, and its proxy keeps 0.33's answers. ReferenceProxy (modelx/core/reference.py) - __eq__ and __hash__ by binding: equal when the other object is a ReferenceProxy, of either class, and o._impl is self._impl; hash(id(self._impl)). On 1d92c67 two proxies to one Reference were unequal and {a, b} had 2 elements; now 1. copy.copy keeps equality. For an object that is not a proxy __eq__ returns False, not NotImplemented. With NotImplemented, which object.__eq__ gave on 1d92c67, Python asks the other operand: proxy == P.h raised TypeError from Cells.__eq__ for a Cells with parameters, and proxy == P.sc ran the formula of a scalar Cells (len(tracegraph) 1 -> 2). Now both are False and nothing is evaluated. No code in modelx, modelx-bridge, modelx-mcp (lifelib-app 098c7f8), spyder-modelx or spymx-kernels compares proxies, keeps them in sets or dicts, or relies on identity equality; ObjectNode compares impls. - _is_valid(): True only while impl.parent.interface._impl is impl.parent and impl.container.get(impl.name) is impl. It never asks the parent interface's _is_valid(), and does not raise on a proxy whose impl is not a ReferenceImpl (a pre-T5 slot, or None for P.r = PX): it gives 0.33's answer, True. A closed model's bindings stay valid. Re-run against this commit: - fix-final/e03 with the resolved-slot prototype (proto.py fix2): the new _is_valid() equals the impl ("owner") test in 70 of 70 cases, 10 scenarios x 7 bindings; the interface ("design") test differs in 9, the kept slot, argument and formula ref after del P[3]; P[3], after P.clear_items(); P[3] and after a rebind of P.rel and P[3]. Without the prototype the same, except that the slot answers True. - refute2/r08b: the new answers equal the impl test for 18 of 18 (3 states x 6 bindings); r08: after del P[3]; P[3] the old slot and argument proxies are False, the new ones True, old != new. - fix-used-by/u04 through proxies: after P.clear_items() the container test is still True for the argument, the formula ref and the item's _self, and _is_valid() is False; after a rebind of B.k and of a global, both are False for the Space, derived and global bindings. On 1d92c67 _is_valid() was True after every one of these edits. repr() of a proxy whose binding is gone is now '<ReferenceProxy null object>', as Interface.__repr__ asks _is_valid(). - _refmodes = ('auto', 'absolute', 'relative'), a class attribute. - _idstr and _get_repr defined on the class, answering as forwarding did: on 367 proxies (a synthetic model with slots, nested items, zero-parameter and tuple-argument items and the P/PX case: 200; simplelife with Projection(1), Projection(2, 1), Economic(1): 133; BasicTerm_SE with Projection[1], [2]: 34), _idstr, _get_repr in four argument combinations, _evalrepr, repr() and _is_valid() of a live proxy were identical on 1d92c67 and on this commit, the P/PX proxy's AttributeError messages included. No _get_referents or _get_formula_links: forwarding still raises AttributeError. - refmode's docstring states what each kind returns, measured: 'auto', 'absolute' or 'relative' for UserSpace References (assignment and new_space(refs=) 'auto'), their copies and the binding an item shares; 'auto' for a formula ref; None for a global (also through a Space or an item), an argument and _self, _space, _model. Known limitations: False for new_pandas, new_module and new_excel_range References in a UserSpace and their copies; after read_model, what the file holds (below). F2 (modelx/core/space.py): UserSpace.set_ref raises ValueError for a refmode that is not a str in _refmodes ('sideways', None, 42, 'AUTO', '', ('auto',)) before set_attr, so nothing changes. On 1d92c67 each was stored, and making a sub Space of a Space whose Cells-valued Reference had one failed with "ValueError: must not happen". absref and relref pass constants; new_pandas, new_module and new_excel_range go through the impl's set_attr and are unaffected. The check is skipped while System.serializing is set, which the plan did not foresee. Every reader passes set_ref the mode its file holds: - serializers 4-7 write a Reference whose value is an IOSpec's as ("IOSpec", value id, spec id), and their readers pass the spec id, an int, as the refmode. Reading lifelib's BasicTermASL_ME, BasicTerm_SC, BasicTerm_ME_for_Cluster, ifrs17sim, nestedlife and solvency2 makes 3, 3, 3, 13, 13 and 17 such calls; with the check applied to the reader all six fail with ValueError (BasicTerm_S, v8, reads); write_model(version=6) and (version=7) of a model with a UserSpace new_pandas produce the same; - a model saved by 0.33 with set_ref('ri', S.foo, 'sideways'), None or 42 holds "sideways", "None" or "42", reads and computes on 0.33, and would not read. With the exemption all of them read as on 1d92c67, with the same refmodes. The int refmode is a reader defect, recorded for later. Tests - core/reference/test_refproxy.py (37 new): equality and hash of 20 bindings (global, through a Space, Space, derived, the binding an item shares, the _self, _space and _model of two Spaces, an item and a DynamicSpace in it, argument, formula ref) from fresh proxies, get_object, _get_object, ReferenceNode.obj and copy.copy; unequal bindings; never equal to non-proxies, with len(tracegraph) unchanged; _is_valid live, False after 8 edits (rebind and delete of a Space Reference and of a global, delete of a Space, del P[1], clear_items(), a rebind in P) with the unaffected bindings still True; still False after del P[3]; P[3], clear_items(); P[3] and a rebind and P[3]; a bool, and no raise, for pre-T5 slots and a whole-model _get_attrdict(['_is_valid']); a closed model's bindings valid; repr of an ended binding; _refmodes; refmode by kind; F2's ValueError for six modes on a new and an existing Reference, which keeps its value, mode, binding and computed values; each valid mode, absref, relref. On 1d92c67, 29 of the file's 38 tests fail. - serialize/refmode/test_refmode.py (8 new): a v6 and a v7 model with UserSpace new_pandas and new_module References reads; v6 and v8 files holding "sideways", "None" or "42" for an Interface Reference read and compute. Without the exemption all 8 fail with ValueError; on 1d92c67 all 8 pass, as reading is unchanged. - No existing test changed. Golden (regenerated with python -m modelx.tests.core.api.test_tool_api_surface --write): on ReferenceProxy and DynamicReferenceProxy, _idstr (property), _get_repr (method, "(self, fullname=False, add_params=True)") and _is_valid (method, "(self)") move from "forwarded" to "members", now class attributes with the same kind and parameters, and _refmodes (attribute) is added. The spyder snapshots (test_spyder_surface.py, test_spyder_requests.py) are unchanged. Full suite (CPython 3.11.15): 1916 passed, 8 skipped, 1 failed (export/test_lifelib.py::test_assets, QuantLib missing), against 1871 passed, 8 skipped and the same failure on 1d92c67. lifelib-app's modelx-bridge suites: 835 passed, 1 skipped (the lifelib drift check). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
…test PR 3 of devnotes/ToolAPIDesign.md: T5's resolved slot (decision 7, as recommended) and the fixes to DynamicSpaceImpl.wrap_impl. Measured against a copy of 1d92c67 ("base") on CPython 3.11.15; probes in the session scratchpad, pr3/slots/. Resolved slots (modelx/core/dynamic.py) - _init_dynbaserefs wraps what wrap_impl returns when it is not a ReferenceImpl: ReferenceImpl(dynamic Space, name, the copy's interface, container=_dynbase_refs, is_derived=True, refmode=the binding's), in the existing _dynbase_refs dict. No new slot. On base the slot held the copy's impl, so P[1].rel (P.rel = P.Child) had the name 'Child', _idstr 'P.__Space1.Child', refmode raised AttributeError, it stayed _is_valid() after del P[1], and _space.rel in a formula of P[1] failed the assert in Namespace.__getattr__. - DynamicSpaceImpl.on_update_ns: after BaseSpaceImpl's loop, a slot whose value is a Space of the tree gives formulas that Space's namespace, as the raw impl did on base; a Cells already gives the Cells. On a synthetic model with nested items and on simplelife with Projection(1), (2, 1) and Economic(1), all 402 ns_dict entries of the dynamic Spaces were the same objects on base and branch. Without the rule ns_dict held the interface and recomputing P[1].h() (reads rel.w()) cost 10.48-10.88 us against 9.35-9.95 us with it. Through P[1], nested P[1][5] and P[1].Child, measured on 8 slots (rel, a relative rr, a Cells relc, the root me, P[1].Child.up, .sib, and the nested ones): name the slot's, parent the dynamic Space, _idstr 'P.__Space1.rel' and 'P.__Space1.__Space3.rel', _evalrepr 'V1.P(1).rel', 'V1.P(1)(5).rel', _get_repr() 'rel' (base: 'Child', 'h()', 'P[1]'), value the in-tree copy (unchanged), class DynamicReferenceProxy (base: ReferenceProxy), _is_derived() and is_derived() True (base: None), refmode the binding's (base: AttributeError), r.parent.bases[0]._get_object(r.name, as_proxy=True) the binding (base: the binding of the copy's name, such as 'P.Child', or IndexError, NameError, or a FormulaError from evaluating P.h). P[1].rel != P[2].rel != P.rel; len({P[1].rel, P[2].rel, P.rel, P[1].rel again}) is 3. _is_valid() False after del P[3], clear_items() and a rebind (P.k = 30, P.rel = P.Child), and still False after P[3] is made again (base: True in all); repr '<DynamicReferenceProxy null object>'. Formulas reading _space.rel, _space.relc and rel.up.k (a slot through a namespace) work; on base all three raised AssertionError. Every proxy of every refs view of the synthetic model (28) answers _is_derived(); 10 gave None on base. Re-runs: fix-reference-identity/g02 on the real code (no prototype) prints what its fix2 prototype run printed, apart from PR 2's class names and F1's labels: 44/44 objects, 75/75 proxies, 19 slots; refute2/r08 and r08b, fix-final/e03 and fix-used-by/u04 print what their prototype runs printed (e03: _is_valid() equals the impl test in 70 of 70). simplelife: 7 resolved slots per Projection item (pol, asmp; PremTerm; gen, polt, prod, sex), 21 for 3 items, as g03b; BasicTerm_SE with 2 items, BasicTerm_ME, CashValue_ME, BasicTerm_S: 0. Values and node counts equal on base and branch: simplelife PV_NetCashflow, PV_Check, PV_SumInsurIF of Projection[1..3] and 5,142 nodes; PV_NetCashflow(0) alone 8954.018303, 7511.092085, 9173.90659 and 5,034 nodes; BasicTerm_SE Projection[1].pv_net_cf() = 108625.005624, 2,416 nodes. precedents() of 734 simplelife Cells nodes equal, after masking memory addresses. _check_sanity passes after the deletes. Costs (min of 7, 3 processes each, base then branch): P[1].h() recompute (g07) 9.09-9.22 vs 9.34-10.67 us, and in a second run of 5 with a control Cells 9.32-11.40 vs 9.38-9.69 us (control 6.29-7.38 vs 6.41-7.25 us); no namespace is rebuilt in the loop on either. 1,000 BasicTerm_SE Projection items: 545-653 vs 583-596 ms. 100 simplelife Projection items: 180-196 vs 179-189 ms. Persistence of a model with slots after items exist: pickle.dumps(model) raises AttributeError: 'UserSpaceImpl' object has no attribute '_global_names', on base and branch alike; write_model and zip_model write byte-identical files on both; read_model of either rebuilds the item that holds an input, whose slot is then a resolved slot. wrap_impl - The in-tree test has a dot boundary: impl == root or impl.startswith(root + '.'). On base it was root == impl[:len(root)], so for P.r = PX the slot held None: every formula of P[1] raised AttributeError ('NoneType' object has no attribute 'interface'), and the dicts of P[1], of P[1].refs (_get_attrdict, _baseattrs, _baseattrs_private) and of the Model raised it too ('... no attribute 'name''). Now P[1].r is the binding 'P.r', P[1].h() works (g06: 11) and none of them raises. With relref, P[1] is refused as for any other sibling, "ValueError: 'PX' referred as 'P.r' is out of 'P'" (refute2/r16; base made P[1] and its formulas raised AttributeError). - No more value.direct_bases[0] on a ReferenceImpl. The path: a derived 'auto' Reference whose relative value is outside the item's tree, as Y.P(X.P) with Y(X) and X.P.r = X.Other, which Y.P sees as Y.Other. Making Y.P[1] raised "AttributeError: 'ReferenceImpl' object has no attribute 'direct_bases'" on base. It now returns the binding, as for a defined Reference: Y.P[1].r is Y.Other and Y.P[1].f() is what Y.P.f() is. - Not in the plan: a value whose name is in the tree but which the tree has no copy of, an ItemSpace such as P.r = P.Child[3]. On base the slot held None, with the failures of the prefix case; wrapping it would have raised when the ItemSpace was made. It now keeps the binding, so P[1] sees P.Child[3], as P does. Docstrings (modelx/core/reference.py): ReferenceProxy.__new__, refmode (the AttributeError of slots and of the prefix case is gone; a versionchanged), _is_derived, is_derived, _evalrepr, _idstr, _get_repr, _is_valid and DynamicReferenceProxy describe resolved slots, and drop the known limitations they fix. The isinstance guards in __new__, _is_derived and _is_valid stay, for a proxy made by hand; modelx makes none over a non-Reference now. Tests changed where the plan says the behaviour changes: - core/space/inheritance/test_tool_flags.py: PROXIES' P[1] and P[1][5] rel and relc are DynamicReferenceProxy (were ReferenceProxy); test_is_derived_where_no_reference_is_held becomes test_is_derived_of_resolved_slots (True, 'generated'; was None); test_is_derived_none_through_a_dynamic_space becomes test_is_derived_through_a_dynamic_space (up, side, rw True and DynamicReferenceProxy; out, fixed as before); DERIVED_REFS gains 4 slot rows; module and test_whole_model_walk docstrings. - core/reference/test_refproxy.py: the fixture's P gains rel -> P.Child, and item_bindings and ITEM_LABELS a "resolved slot", so the equality, edit, made-again and refmode tests cover it; test_is_valid_where_no_reference_is_held (which pinned only a bool) becomes test_is_valid_of_item_rows_in_the_whole_model_walk (True while live, False after del for the slots; the PP/PPX row no longer needs PP deleted before the walk); test_unequal_bindings adds the slots. New: core/reference/test_resolved_slots.py, 18 tests: the slot table above, equality across _get_object, get_object, a ReferenceNode's obj and the refs view rows, what formulas see, the bindings that are not slots, liveness, the whole-model walk, the prefix case and its relative variant, the derived out-of-tree path, the no-copy value, and lifelib's simplelife (values gated on its SHA-256, as test_tool_contracts does for BasicTerm_S). On 3396cba all 18 fail, and 16 of the changed tests in the two files above. Not here: the _idstr/_address round trips (PR 4). No golden changes: tool_api_surface.json, spyder_requests_snapshot.json and spyder_surface_snapshot.json are unchanged and their tests pass (no fixture of theirs has a resolved slot). Hot path untouched: trace.py, cells.py and base.py are identical to 1d92c67. Every changed file parses with ast feature_version=(3, 9). Suite: 1 failed, 1938 passed, 8 skipped (only test_assets, QuantLib), against 1916 passed at 3396cba. lifelib-app 098c7f8's modelx-bridge suites: 835 passed, 0 failed, 1 skipped. Docs build: the same 3 warnings as PR 2's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
PR 3 of devnotes/ToolAPIDesign.md: T4. Measured on CPython 3.11.15;
probes in the session scratchpad, pr3/t4/.
New modelx/core/inheritance/query.py, get_inheritance(impl), and
BaseSpace._get_inheritance() on UserSpace, ItemSpace and DynamicSpace
(versionadded 0.34.0). It returns new containers on each call:
- 'bases': as bases (C3 MRO); [dynbase] for a dynamic Space;
- 'direct_bases': as _direct_bases;
- 'cells': {name: {'state', 'defined_in'}} in the order of cells;
- 'refs': {name: {'scope', 'state', 'defined_in'}} in the order of refs.
state is 'defined', 'overriding', 'derived', or None for scopes
'argument', 'formula', 'global' and 'builtins'. defined_in is the Space
for 'defined' and 'overriding', the first base in the MRO whose member
is defined for 'derived' (the base InheritanceSync.reconcile derives
from), the Model for a global, None otherwise. Scopes follow the layers
of refs_outer in lookup order, so a name an earlier layer hides gets
the scope of the binding in use: UserSpace own_refs ('space'); dynamic
_allargs ('argument'), own_refs ('formula'), _dynbase_refs ('base',
resolved slots included); then _global_refs ('global', 'builtins' for
__builtins__). sys_refs is not a layer, so _self, _space and _model are
never reported. A dynamic Space is read through _dynbase: one MRO walk
per call, no value read, so nothing evaluates and a derived relative
Reference to a base's child Space (a null Space) is reported 'derived'
without being resolved.
Checks against the design's prototypes and PR 1's 0.33 recipes:
- inheritance/i05 (Base1, Sub, Multi, Deep, Plain, Sub[1]) and i12
(P[1], P[1].Kid, R[1] with {'base': PP}): the states and scopes,
printed in the prototypes' format, are identical to i05_out.txt and
i12_out.txt. R[1]'s argument is j, R's parameter, though
R[1].parameters is P's ('i',).
- defined_in, states, scopes and order equal test_tool_contracts'
cells_recipe and refs_recipe on 9 of 9 synthetic Spaces and on 25 of
25 Spaces of BasicTerm_S, BasicTerm_SE (2 items each),
BasicTerm_ME, BasicTermASL_ME, CashValue_ME and simplelife
(Projection(1), (2, 1)); len(tracegraph) unchanged on all.
- Only one static edit leaves an ItemSpace alive with different cells:
sort_cells() reorders the static Space's and not the item's (13 edits
tried), so a dynamic Space's 'cells' are keyed in its own order.
- A deleted Space raises DeletedObjectError, as bases does; a closed
model's Spaces give the answer they gave before close().
Cost, every UserSpace of the model (min of 7 x 200 in 5 alternating
rounds, 3 processes), against i04's states-only snippet with one MRO
per Space in the same processes (i04 recorded 9.6, 58.3 and 112.7 us):
BasicTerm_S 17.1-18.9 us against 7.2-8.1 us
BasicTermASL_ME 107.6-110.5 us against 44.2-46.9 us
simplelife 164.1-171.5 us against 77.2-82.0 us
and per-member Derivable.bases 286-302, 551-596 and 1,325-1,340 us.
The extra over the snippet is a dict per member, the refs scopes and
both base lists; the graph's MRO is 22-33 of the 81 us a call takes on
simplelife's Projection (2 bases, 93 Cells), as bases costs. Two
BasicTerm_S items: 39-43 us; six simplelife dynamic Spaces: 194-202 us.
A first version took 33.9 / 155.7 / 272.6 us in one run; a set of
base names, the _is_derived slot, one dict per member, and no second
graph query for a Space with an empty MRO brought it down.
_own_refs on a DynamicSpace (section 9, "Found while implementing PR
1", assigned to T4): kept as it is, the own_refs layer, which
toolapi.rst already documents and test_tool_contracts pins
(test_own_refs_in_dynamic_spaces). Evidence:
- no consumer reads it: 0 hits in modelx_bridge and modelx_mcp
(lifelib-app 098c7f8), spyder-modelx 0406582, spymx-kernels 2b3d52c
and the public modelx-bridge checkout; in modelx only the
serializers' SpaceEncoder, which encodes UserSpaces only;
- PR 1's 0.33 fallback recipe tells 'formula' from 'base' by it. With
_own_refs widened to own_refs + _dynbase_refs on dynamic Spaces
(patched in a probe), the recipe reported every 'base' Reference as
'formula': 55 of 186 names (5 synthetic, 10 BasicTerm_S, 12
BasicTerm_SE, 28 simplelife), against 0 of 186 as it is;
- with T4 the relation is exact: set(_own_refs) is the names of scope
'space' in a UserSpace and 'formula' in an ItemSpace, plus a formula
ref an argument hides, and empty in a DynamicSpace (31 of 31 Spaces,
synthetic and lifelib). The gap the row describes, names in a
dynamic Space's refs that _own_refs lacks, is 'base' and 'argument'
(55 and 23 names on those models), which T4 now reports.
The _own_refs docstring ("A mapping associating names to self refs.")
now says what it holds on each kind and points to _get_inheritance.
Tests: new modelx/tests/core/space/inheritance/test_get_inheritance.py,
37 tests: the i05 and i12 tables with defined_in and both base lists;
the i08 regression (Sub[1] beside a one-letter Space S: bases [Sub],
foo 'defined'); '_' globals, a '_' new_space(refs=) Reference, a '_'
argument and a '_' formula ref under their scopes; __builtins__ scope
'builtins' and no system name in any Space; resolved slots scope
'base'; the base chosen by a Space formula; a hidden formula ref; the
derived relative Reference to a null Space; len(tracegraph) and every
Cells' len unchanged; new containers at every level, a mutated result
changing nothing; the sort_cells() order; DeletedObjectError; the
_own_refs relation; agreement with the 0.33 recipes. Six mutants of
query.py (graph read with the item's idstr, one shared base list,
formula refs before arguments, the last defining base, the static
order for a dynamic Space, reading each Reference's value) each fail
1 to 14 tests; the i08 test fails when T4 reads the graph with the
item's idstr and the graph lacks F6's guard.
Signature golden (test_tool_api_surface.py, regenerated with --write):
FROZEN gains ("T4", SPACES, ("_get_inheritance",)), and the golden
gains three entries, UserSpace, ItemSpace and DynamicSpace
._get_inheritance, kind "method", signature "(self)". Nothing else
in it changed. The spyder snapshots are unchanged. No existing test
was changed.
Full suite: 1 failed (export/test_lifelib.py::test_assets, QuantLib
missing, as at 1d92c67), 1975 passed, 8 skipped; 393214e had 1938
passed, and the 37 new tests account for the difference. lifelib-app
098c7f8's modelx-bridge suites against the branch: 835 passed, 0
failed, 1 skipped. Hot path (trace.py, cells.py, base.py) unchanged
against 1d92c67. Sphinx build: the same 3 pre-existing warnings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
PR 3 of devnotes/ToolAPIDesign.md: F10 (section 3.3). Measured on CPython 3.11.15 against 0.33.0 (4fa720f), 1d92c67 and 6bec1e3; probes in the session scratchpad, pr3/f10/. 1. UserSpace.set_ref, and absref and relref through it, raise AttributeError("'a' is already defined as a Cells" / "... as a Space") for the name of a Cells of the Space, defined or inherited, with or without parameters, or of a child Space. Nothing changes. Before (0.33 and 1d92c67, probe f01): a Cells with no parameters had its input set and no Reference was made, by all five routes, also with a Space as the value and for a Cells inherited from a base; a Cells with parameters raised AttributeError "Cells 'p' is not a scalar."; a child Space raised ValueError with an empty message. Exception type: AttributeError for both, the type the set_ref docstring already gave ("AttributeError: If name conflicts with an existing attribute"; its name argument "must not conflict with existing cells or spaces"). toolapi.rst and reference.rst give no type for these clashes, and no test pinned the child Space's ValueError, so no documented behaviour changes; the docstring's Raises now names the members and a versionchanged records the old results. Child Spaces are not inherited on 0.33 (S.spaces stays empty after add_bases), so only a defined child Space can clash. Unchanged: F2's refmode check runs first; space.a = 3 still sets the input; space.p = 3 and space.Child = 3 still raise; set_ref on its own Reference, a global's name, a new name, and a sub Space's Cells ("Cannot create reference 't'", ValueError) behave as before. The check does not run while System.serializing is set, as with F2. 0.33 can save a UserSpace that holds a Reference and a Cells of one name (S.c = Other, then S.add_bases(B) with Cells B.c), and its reader restores a Reference to a modelx object with set_ref, which sets the Cells' input (probe f02, same on 0.33 and the branch). With the check applied during reads that file fails with AttributeError (f02b); with the exemption it reads as on 0.33. 2. SpaceManager._can_add refuses a macro's name for a Model parent: the Model's namespace holds Spaces and global References only. This covers Model.new_space ("Cannot create space 'mac'"), UserSpace.rename ("Cannot rename 'S' to 'mac'") and UserSpace.copy(model, 'mac'). All three were accepted on 0.33 and hid the macro (m.mac was the Space). new_space() without a name now skips a macro's name: with macro Space1 it makes Space2, where 0.33 made Space1 over the macro. new_macro and m.mac = v already refused the reverse; a child Space may still have a macro's name. No saved model depends on the old behaviour (probe f03, fix-integrate/i01 widened): 0.33 wrote all 24 files (3 routes x write_model and zip_model x default, v6, v7, v8). The 18 default, v7 and v8 files fail to read on 0.33 and on the branch alike, ValueError: Name 'mac' already used, with no model left open: readers 7 and 8 make the Spaces before the macros. The 6 v6 files read on both, identically, because the v6 writer drops macros, so the file holds only the Space. The check cannot fire inside a read for the same ordering reason. 3. EditableParent.__setattr__ tests attr.fset is not None. Every property has an fset attribute, so hasattr passed and assigning to a read-only property called None. Found by code (property with fset None, on dir() of the class): 23 on UserSpace (13 public, 10 underscore: _baseattrs, _cells, _direct_bases, _evalrepr, _idstr, _idtuple, _name, _named_itemspaces, _own_refs, _parent) and 16 on Model (10 public, 6 underscore), the same on 0.33 and 1d92c67. All 39 raised TypeError: 'NoneType' object is not callable; now AttributeError: <name> is read-only. The design's 13 and 10 counted public names only. Settable properties (doc, allow_none, formula, parameters, path) and methods ("... is not a property") unchanged. lifelib 0.17.2 (probe f04): 81 model folders ship a _system.json (57 in the national libraries' products/); 80 read, and BasicBonds needs QuantLib on 1d92c67 too. During those reads modelx made 234 set_ref calls, 202 Model-level _can_add calls and 2,008 EditableParent __setattr__ calls; none had a name a new refusal covers (0 Cells or child Space names to set_ref, 0 macro names, 0 read-only properties). The digests of the 80 models read (Spaces, Cells, refs with refmodes, input counts, macros) are byte-identical on 1d92c67 and the branch. No lifelib model has a macro. Design probes rerun on the branch: v03 now refuses set_ref('a') and new_space('mac') (its follow-up section assumes acceptance and stops there); v01b reports AttributeError for the 13 + 10 public read-only properties, and TypeError only for parameters = 12345 and path = 12345, which are value errors of settable properties; i01 stops at new_space('mac') with ValueError. Tests: new modelx/tests/core/space/test_name_clash.py, 75 tests. On 6bec1e3, 65 fail and 10 pass (the tests that pin unchanged behaviour). Removing the read exemption fails one test, test_read_keeps_a_reference_named_like_a_base_cells. No existing test changed and no golden changed: set_ref's signature is unchanged and test_spyder_surface's snapshot is byte-identical. Full suite: 1 failed, 2050 passed, 8 skipped (test_assets, QuantLib); 6bec1e3 had 1975 passed. lifelib-app 098c7f8's modelx-bridge suites: 835 passed, 0 failed, 1 skipped. Changed files parse with feature_version=(3, 9); trace.py, cells.py and base.py are unchanged since 1d92c67. Sphinx: no new warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
… F2/F10) The reference page, reference.rst, docstrings, release notes and design record for the four PR 3 commits 3396cba..46fb8d8. No code changes behaviour: only docstrings change in reference.py and space.py (their code, docstrings stripped, compares equal to 46fb8d8's), and no test or golden changes. Every statement was probed on the branch, on a worktree of 1d92c67 and on 0.33.0 (scratch probes d01-d05 under pr3/docs/). Before values are 0.33's; where 1d92c67 differs it is by PR 2's classes only. toolapi.rst ("API for tools"): - The page's model gains proj.rel = child, so the examples show a resolved slot (item.rel, 'Proj.__Space1.rel'). - New section "References" (toolapi-references): - equality and hash by binding: a == b True and len({a, b}) 1 for two proxies of Base.rate (1d92c67: False, 2); a global's proxy equal through the Model, a Space and an item; never equal to a non-proxy, with nothing evaluated (proxy == scalar Cells moved len(tracegraph) by 1 on 1d92c67, 0 now); cells == proxy is still Cells.__eq__ (TypeError, or an evaluation); - refmode per kind and _refmodes, F2's ValueError, with the read exemption; a Known limitation box for False (new_pandas etc.), the int after reading a v6/v7 file (2 in d01) and the str of an old invalid mode ('sideways', 'None', '42', written on 1d92c67 and read on the branch, d02); - "Resolved slots" (toolapi-resolved-slots): what a slot is, its name, parent, _idstr, _evalrepr, class, _is_derived, refmode and value, the binding through parent.bases[0], and a table of what each name seen through an ItemSpace is; versionchanged with 0.33's values. - Identity: the intro and _idstr name the members the proxy now defines and the slot; _is_valid() says when a proxy turns False (rebind, delete, Space deleted, base rebound, item deleted, by del, clear_items() or a rebind in its Space or of a global) and stays False after the item is made again, with doctests; repr null object. Its box for References is removed. The Macro box and the closed-Model box stay (both still True, probed) and the revived-item box now says a proxy of the old item stays invalid. ReferenceProxy._idstr, _get_repr and _is_valid join the autosummary. - Detection: the forwarded-members box now uses _idtuple (_idstr is a class member), with a versionchanged. - Kinds: DynamicReferenceProxy row and "Dynamic objects" include resolved slots; the item-copy box is removed. - "What a kind can do": F10's refusals (set_ref/absref/relref on a Cells or child Space name, a Model Space on a macro's name) and the read-only property AttributeError, with a doctest and versionchanged. - Inheritance: _is_derived True for slots (box removed), is_derived()'s versionchanged gives 0.33's AttributeError/True; a new _get_inheritance() entry (keys, states, defined_in, scopes, what is not reported, DeletedObjectError, cost 17-19 / 108-111 / 164-172 us, detection and the 0.33 recipe) with UserSpace, ItemSpace and DynamicSpace rows; _own_refs points to the scopes, with a doctest. - Wire: the prefix box (label toolapi-prefix-ref) and the two-records box are removed, replaced by a versionchanged; the _is_derived extattr row drops None; "ReferenceProxy forwarding" lists the members the class defines and shows a slot's name, fullname, parent, _idtuple. - _get_object and _get_from_name: the prefix boxes and see-also go (P[1]._get_object('r') gives PX, _get_from_name('P.__Space1.r') PX). reference.rst: the parent bullet names the ItemSpace's copies; the note under reference-proxy-identity describes the dot boundary and resolved slots, with an example, and its Known limitation becomes a versionchanged; Reference modes gain _refmodes, F2, the system names' None, the slot's mode, and the int/str after reading. Docstrings: ReferenceProxy._refmodes links refmode by its full name (the autosummary line left it unresolved); refmode says "the default format before modelx 0.32"; _is_valid's versionchanged covers every Reference an item makes and the repr; _is_derived and DynamicReferenceProxy link toolapi-resolved-slots; set_ref's Raises names _refmodes and its versionchanged the read exemption; _get_inheritance's defined_in sentence reworded. relnotes_v0_34_0.rst: - Enhancements: ReferenceProxy as a tool object (equality and hash, _is_valid, _refmodes, _idstr/_get_repr on the class), resolved slots, _get_inheritance with its cost. - Backward Incompatible Changes: proxy == and hash; _is_valid False for stale bindings and the null-object repr; the slot proxy with before and after name, fullname, _idstr, _evalrepr, _get_repr, refmode, is_derived, class, _is_valid and parent (and the root and Cells variants); set_ref's ValueError; set_ref/absref/relref on a Cells or Space name; new_space, rename and copy on a macro's name and new_space() skipping it; read-only property assignment. - Bug Fixes: the prefix case (P.r = PX, also a Cells or Space inside PX and a child of P holding it; probed on 0.33, 1d92c67 and the branch), the direct_bases path, the in-tree value with no copy, and slots read through a namespace (_space.rel, rel.up). - PR 2's entries revised: DynamicReferenceProxy includes slots; _is_derived drops the None case; the is_derived() bug fix now says True for slots and False for the prefix binding. devnotes/ToolAPIDesign.md: the Progress paragraph records PR 3 (five commits on 1d92c67, 2,050 passed) and that decision 7 awaits the owner; decision 7's tracker row; the PR 1 and PR 2 rows assigned to PR 3 now say what PR 3 did; a new section 9 table "Found while implementing PR 3 (2026-10-18)" with 27 rows from the stages' findings, each with what picks it up; "Not measured" no longer calls T5's slots a prototype, and the RefView inference is now measured. Checks: - Fresh Sphinx build after deleting the generated stubs: "build succeeded, 3 warnings" (_static, installation.rst:164, eval_formulas.rst), main's three. Every new autosummary row generates a page with its docstring; toolapi.html, reference.html and the release notes have no unresolved reference except _get_attrdict() in the summary lines of ItemNode/ReferenceNode._baseattrs, from node.py, unchanged since 1d92c67. - python -m doctest on toolapi.rst: 114 passed (78 at PR 2). The reference.rst examples under reference-proxy-identity: 15 passed. - Full suite with -n 3 on CPython 3.11.15: 1 failed, 2050 passed, 8 skipped (export/test_lifelib.py::test_assets, QuantLib missing), as at 46fb8d8. The changed .py files parse with feature_version=(3, 9); trace.py, cells.py and base.py are identical to 1d92c67. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
DynamicSpaceImpl.on_update_ns (393214e) put a resolved slot's namespace into ns_dict after BaseSpaceImpl.on_update_ns had run its Cells loop, so a slot beat a Cells of the same name, where the base loop, 1d92c67 and the prototype (fix-reference-identity/proto.py fix2, which set it inside the refs loop) let the Cells win. add_bases checks no names, so the state is reachable and passes _check_sanity: B.c a Cells, S with formula lambda i: None, S.c = S.Child, S.add_bases(B), S.h = 'lambda: c() + 1'. On 1d92c67 S.h() and S[1].h() gave 2; on a70e7e2 S[1].h() raised FormulaError (AttributeError: 'NoneType' object has no attribute 'signature'), as c in S[1] was S[1].Child's namespace. That broke T5's "formulas see exactly what they see today" and 393214e's message, which said the override gave the prototype's result. The override now skips a name in self.cells. With it S[1].h() is 2 again, and slots/v04's census, every ns_dict entry of the dynamic Spaces of a synthetic model and of simplelife's items, 402 in all, is identical to 1d92c67's (diffed). The override had no test of its own: with it reduced to the base call, or without its hide test, the full suite still passed (review-plan mutate.py). test_resolved_slots.py now pins each of its conditions, checked by patching the override in a pytest plugin: - test_what_formulas_see: in P[1] and P[1][5], `rel is _space.Child` is True, and P[1]'s `lambda: out` is Other. With the override reduced to the base call, isrel() is False. - test_slot_hidden_by_argument_or_formula_ref (new): P.i = P.Child and P.rel = P.Child under the Space formula lambda i: {'refs': {'rel': 2 * i}}; P[1]'s formulas see (1, 2). Without `refs[name] is ref`, both were P[1].Child's namespace. - test_cells_and_slot_of_one_name (new): the add_bases shape above; S[1].h() == S.h() == 2. Without `name not in cells` (a70e7e2), it raised FormulaError. - Without `ref.container is slots`, 14 tests of the file fail. The two new tests pass on 1d92c67 as well, and so do the new lines of test_what_formulas_see (probe fixer/f01_cases.py: True, True, 1, 2). The slots fixture gains two Cells, isrel() and seenout(); no existing assertion changes. The hot path is untouched: trace.py and cells.py are byte-identical to 1d92c67. Full suite with -n 3 on CPython 3.11.15: 1 failed, 2052 passed, 8 skipped (export/test_lifelib.py::test_assets, QuantLib missing, as on 1d92c67). lifelib-app's bridge suite: 835 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
test_read_iospec_refs_of_a_space and test_read_a_mode_set_ref_took_before_034 (test_refmode.py, 3396cba) closed the model they write without model._impl._check_sanity(), which every new fixture's teardown runs before close(); the model they read back was already checked. Both now check it, as test_name_clash.py's reader test does. The 9 tests of the file pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
…wners Each statement was probed on the branch, against 1d92c67 and, where it says so, 0.33.0 (4fa720f); probes under scratchpad pr3/fixer and the reviewers' pr3/review-*. toolapi.rst - _idstr: a Reference an ItemSpace makes has the _idstr of its parent, the ItemSpace or the DynamicSpace in it, then its name; the page said the ItemSpace's. P[1].Child._get_object('up', as_proxy=True)._idstr is 'P.__Space1.Child.up', as test_resolved_slots.py's SLOTS table pins. - _is_valid(): the edits that delete an item's ItemSpaces include a new Reference, not only a rebind, and a Reference of a base of its Space. fixer/f03_item_edits.py, (items of P, items of Q, arg valid): new or rebound global (0, 0, False); new or rebound Reference of P (0, 1, False); of P's base B (0, 1, False); of an unrelated U (1, 1, True). The release notes' sentence says the same now. - "Takes new child Spaces and References": the refusal is limited to the routes it names. add_bases checks no names (review-docs/p18: S with Cells c and B.c = Other, S.add_bases(B) gives ('c' in cells, 'c' in refs) == (True, True), and so does the reverse), and space.a = 3 sets the input of a Cells a. - refmode's versionchanged, the release notes' F2 entry and set_ref's docstring add that with such a mode a value outside the Space made every ItemSpace of it fail, FormulaError from RuntimeError: must not happen, and that a read model fails the same ways. review-docs/p13 on 0.33 and 1d92c67: S[1].u() fails for C.c outside S and gives 2 for S.inner; p12 written on 0.33 with 'sideways', None and 42 and read on the branch: S.ux(), S.uy() == (1, 2), S[1].ux() and S[1].uy() fail as above, as on 0.33, and a sub Space raises ValueError: must not happen. reference.rst - The dot rule decides "inside"; Space1.Child[3] is inside B by it, and the page called it outside. A value inside B that the ItemSpace has no copy of is referred to as it is in B, whatever the mode: review-docs/p11, P.relref(r=P.Child[3]) makes P[1] with r == P.Child[3] and h() == 3, where P.relref(r=PX) makes P[1] fail. relnotes_v0_34_0.rst - relc's parent was Proj[1].Child (0.33 and 1d92c67) and is Proj[1]; the entry now says so, and that parent was the parent of the copy. ToolAPIDesign.md - §9 PR 1 row on _is_valid: the deleted macro goes to PR 5, beside T8's `del m.mac` path, instead of "not assigned". Not fixed here: MacroImpl.on_delete is `pass`, and with Impl.on_delete in its place (fixer/f02_macro.py) _is_valid() is False but repr(), a call and parent of a kept macro raise DeletedObjectError, where they gave '<Macro Mac.mac>', 1 and the Model, a change §5 does not list. toolapi.rst's Macro box stays, as the page names no PRs. - §9 PR 3 rows: the sideways-mode row adds the ItemSpace failure; the ItemSpace-deletion row gives the edits above; a new row records UserSpace.__delattr__'s hasattr(attr, 'fdel') test (del space.cells, .name, .bases raise TypeError: 'NoneType' object is not callable on 1d92c67 and the branch; del m.name raises KeyError), for PR 4 beside set_property; and a new row records the on_update_ns Cells clash, fixed in a04379a. - The progress line names a70e7e2, a04379a and d3e7850, and gives the full suite as 2,052 passed. A fresh build (generated stubs deleted, sphinx -E) succeeds with the 3 warnings of a70e7e2's build. python -m doctest on toolapi.rst: 114 passed; reference.rst's reference-proxy-identity section: 15 passed. Full suite with -n 3 on CPython 3.11.15: 1 failed, 2052 passed, 8 skipped (test_assets, QuantLib missing). lifelib-app 098c7f8's bridge suite: 835 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
Every '>>>' line of the page's examples was a doctest block of its own,
because a blank line separates them and the paragraph before ended with
a single ':', so Sphinx drew a box around each: the page had 118 boxes,
12 of them for the setup script at the top. The other modelx pages
introduce an example with '::' and an indented block, as reference.rst
and model.rst do.
The 21 examples of two or more blocks now follow that form: the
paragraph before ends with '::' (':' becomes '::', other endings get
' ::', which Sphinx drops), or, after a table or a bullet list, a '::'
line of its own; and the block is indented 4 more where it was at the
paragraph's level. The page now has 37 boxes. python -m doctest still
finds and passes the same 114 examples, every prompt is still
highlighted, and a fresh build gives the same 3 warnings as main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LMVwDKYrkyW1zAbzKSK8Zc
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 3 of the tool-API plan in
devnotes/ToolAPIDesign.md§6. It implements T4, T5, F2 and F10. Decision 7 is implemented as the design recommends and needs your approval (see below).What changes
T5: ReferenceProxy as a tool object (
modelx/core/reference.py)get_object,_get_objector a node'sobj. Before, each proxy was equal only to itself. Comparing a proxy with a non-proxy returns False. On main that comparison could run a scalar Cells' formula, or raise TypeError fromCells.__eq__._is_valid(). It is True only while the Reference's Space still exists and still holds that Reference. A proxy kept across a rebind, a delete or an ItemSpace clear now answers False, and it stays False when an ItemSpace with the same arguments is made again. On main it stayed True in every one of these cases. A closed model's References stay valid._refmodes = ('auto', 'absolute', 'relative')._idstrand_get_reprare now defined on the class. Before, they came through__getattr__forwarding; they give the same results on 367 proxies across three models.refmodedocstring: it is None for global References and ItemSpace arguments.P.rel = P.Child, wherePhas a formula.P[1].relwasP[1].Childitself. Its proxy had the name'Child',refmodeandis_derived()raised, it never went stale, and_space.relin a formula ofP[1]failed an assert.P[1].relis a Reference ofP[1]whose value isP[1].Child. Its proxy is aDynamicReferenceProxynamed'rel', with_idstr'P.__Space1.rel'._is_derived()is True andrefmodeis the binding's.wrap_implfixes:P.r = PX(a sibling whose name starts withP) no longer leavesNonein the slot. On main, every formula ofP[1]raised there.'auto'Reference no longer callsdirect_baseson a ReferenceImpl. On main, making that ItemSpace raised.P.Child[3], is kept as the binding.T4:
BaseSpace._get_inheritance()(newmodelx/core/inheritance/query.py)basesanddirect_bases, plus the state anddefined_inof every Cells and Reference. Each Reference also gets its scope:space,base,argument,formula,globalorbuiltins.F2:
UserSpace.set_refraises ValueError for a refmode not in_refmodes, such as'sideways', None or 42. Before, it stored the value silently, and later failed with "must not happen".F10: three name clashes
set_refwith the name of a Cells or a child Space raises AttributeError. Before, a scalar Cells' name set its input and made no Reference.Model.new_space,UserSpace.renameandcopyto the Model refuse a macro's name with ValueError. Before, the Space hid the macro, and the model could not be read back.TypeError: 'NoneType' object is not callable.The docs (toolapi.rst, reference.rst, the 0.34 release notes) and the design record are updated. The Known-limitation boxes these changes fix are gone: the item-copy proxy boxes, the prefix-Reference note, and the
_is_validrows for References.For your approval: decision 7
When a Space's Reference points inside the Space itself (
P.rel = P.Child), each ItemSpace now gets its own Reference that points at its own copy (P[1].rel→P[1].Child). Before, the ItemSpace held the copy directly. So a tool saw an object namedChildwhere it expected the Referencerel, and couldn't ask for its mode or whether it was inherited.Formulas are unaffected. They see the same objects, give the same results, and build the same number of nodes (simplelife: 8954.018303, 7511.092085, 9173.90659 and 5,034 nodes on both builds).
The cost is one small object per such Reference per ItemSpace: simplelife's Projection items have 7 each, about 840 bytes per item.
Deviations from the plan, with evidence
set_refchecks are skipped while a model is being read.'sideways'mode would fail too.set_ref's documented exception, and no test pinned the old type._own_refson a DynamicSpace is unchanged. Nothing outside modelx reads it, and PR 1's fallback recipe depends on its current meaning._get_inheritance()'s scopes give the full picture instead._is_valid()afterdel m.macgoes to PR 5. Fixing it changes whatrepr()and a call on that macro do.UserSpace.__delattr__on a read-only property, which has the same defect F10 fixed for assignment, goes to PR 4.Checks
test_assets, the same as on main). That is 181 new tests. Run with-n 3and serially..pyfile parses.== 'Cells'checks from PR 2.trace.get_node,tuplize_key,Cells.__call__/__getitem__andCellsImpl.call/get_valueare byte-identical to main.pv_net_cf()over 10,000 points: 396.9 → 386.2 s, with identical sums;_is_valid()is 3× faster;set()of 100 proxies: 0.55 → 10.4 µs, because equality now goes through Python methods. No modelx code hashes proxies.Generated by Claude Code