Skip to content

Add info property for human-readable snapshots of modelx objects#235

Merged
fumitoh merged 7 commits into
mainfrom
claude/implement-interface-info-DpuT9
May 23, 2026
Merged

Add info property for human-readable snapshots of modelx objects#235
fumitoh merged 7 commits into
mainfrom
claude/implement-interface-info-DpuT9

Conversation

@fumitoh

@fumitoh fumitoh commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces a new info property to the Interface base class that returns a lightweight wrapper with a human-readable string representation of modelx objects (Cells, Spaces, and Models).

Key Changes

  • New module modelx/core/info.py: Implements informational repr wrappers for different object types:

    • _InterfaceInfo: Base class for all info wrappers
    • CellsInfo: Displays cells signature, formula source, cached/input values with key-value pairs
    • SpaceInfo: Shows base spaces, parameters, and itemspace children
    • ModelInfo: Lists contained spaces
    • Helper functions for formatting keys, key-value items, and signatures
  • New info property in modelx/core/base.py: Added to the Interface class, returns an appropriate info wrapper via build_info() factory function with comprehensive docstring and usage example

  • Comprehensive test coverage:

    • test_cells_info.py: 15 tests covering Cells info display (formula source, cached/input values, abbreviation of long lists, single-argument key unwrapping)
    • test_space_info.py: 11 tests covering Space info display (bases, parameters, itemspaces, abbreviation)

Implementation Details

  • Info wrappers are lightweight and carry no new state; they format snapshots on-demand via __repr__
  • Imports in build_info() are deferred to avoid circular dependencies at package load time
  • Single-argument tuple keys are automatically unwrapped for cleaner display (e.g., 3 instead of (3,))
  • Long lists of cached values and itemspaces are abbreviated with ... when exceeding 5 items
  • Formula source is displayed with proper indentation; unavailable sources show (source not available)
  • Cached and input values are separated and counted independently

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9

claude added 7 commits May 20, 2026 12:50
Provide a human-readable snapshot of an Interface object via a new
`info` property on the `Interface` base class. The property returns a
lightweight wrapper whose `repr` summarises the object:

- CellsInfo: the cells' fully-qualified signature, is_cached, allow_none,
  formula source, cached-value count, and an abbreviated listing of
  cached key-value pairs.
- SpaceInfo: the space's fully-qualified representation, parameters (when
  defined), the number of ItemSpaces, and an abbreviated listing of
  those item spaces.
- ModelInfo: a basic summary listing the model's child spaces.

Long key-value listings are truncated past five entries with a
"... (N more)" sentinel.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
Update the layout of the wrapper returned by `Interface.info`:

- The header line now uses `ClassName: <repr>` (no angle brackets),
  where ClassName is the actual Interface subclass (Cells, UserSpace,
  ItemSpace, etc.).
- For Cells, formula source is shown in full. Cached values now count
  only computed entries; a separate `input values` section (with count
  and key-value pairs) is shown only when at least one input value has
  been assigned.
- For spaces, parameters are rendered as a signature string with
  defaults preserved and without surrounding parentheses (e.g.,
  `i, j=0`).
- The itemspaces listing now shows only keys as an abbreviated list
  literal (e.g., `[1, 2, 3, ...]`) instead of key-value pairs.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
Insert `_is_derived` immediately after the header line in CellsInfo,
and `bases` immediately after the header line in SpaceInfo, so the
inheritance status is visible alongside the other top-level
attributes.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
- Rename the Cells info field from `_is_derived` to `is_derived`.
- Unwrap single-argument tuple keys in the cached and input value
  listings (e.g. `3: 6` instead of `(3,): 6`). Scalar cells keep the
  empty-tuple key.
- Render the SpaceInfo `bases` field as a list of plain dotted
  fullnames (e.g. `[Model1.Base]`) instead of `<UserSpace ...>` reprs.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
When a cached or input value's repr spans multiple lines (e.g. a
pandas DataFrame or Series), place the value on its own lines
beginning right after the key. Single-line values continue to render
inline as ``key: value``.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
List the new ``info`` property under the Basic properties section of
each Interface subclass reference page (Cells, UserSpace,
DynamicSpace, ItemSpace, Macro) and under Model properties in the
Model reference page.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
Drop the redundant print() wrapper -- the interactive prompt already
displays the wrapper's repr -- and show unwrapped single-argument
keys in the cached values listing to match the actual output.

https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9
@fumitoh fumitoh merged commit 4e3e5ed into main May 23, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants