Add info property for human-readable snapshots of modelx objects#235
Merged
Conversation
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
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.
Summary
This PR introduces a new
infoproperty to theInterfacebase 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 wrappersCellsInfo: Displays cells signature, formula source, cached/input values with key-value pairsSpaceInfo: Shows base spaces, parameters, and itemspace childrenModelInfo: Lists contained spacesNew
infoproperty inmodelx/core/base.py: Added to theInterfaceclass, returns an appropriate info wrapper viabuild_info()factory function with comprehensive docstring and usage exampleComprehensive 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
__repr__build_info()are deferred to avoid circular dependencies at package load time3instead of(3,))...when exceeding 5 items(source not available)https://claude.ai/code/session_01RwTSSE7phKRY2m56zpeZi9