Skip to content

Update snapshot.py to work with MemoryViz 0.9.0 schema#1345

Open
a1-su wants to merge 1 commit into
pyta-uoft:masterfrom
a1-su:snapshot-to-json-format-update
Open

Update snapshot.py to work with MemoryViz 0.9.0 schema#1345
a1-su wants to merge 1 commit into
pyta-uoft:masterfrom
a1-su:snapshot-to-json-format-update

Conversation

@a1-su
Copy link
Copy Markdown
Contributor

@a1-su a1-su commented May 26, 2026

Proposed Changes

This PR updates the snapshot_to_json function in the snapshot.py file to handle the changes to the MemoryViz expected JSON input in the 0.9.0 update. More specifically, only two updates needed to be made:

  • .frame / FrameDrawnEntitySchema types no longer have an id attribute, so that was removed
  • .class / ClassDrawnEntitySchema types only allow records for the value field, and since we previously were using the .class to represent a Python type, such as int, str, or dict, their repr can no longer be used as the value
    • This has instead been changed so that the name of the entity is the type (ex. int, str, or dict), while the value attribute is left blank
Screenshots of your changes (if applicable)

Sample Setup

if __name__ == "__main__":
    number_var = 67
    type_var = int

Old MemoryViz (0.7.0) SVG

Converted JSON Payload
[
    {
        "type": ".frame",
        "name": "__main__",
        "id": null,
        "value": {
            "number_var": 1,
            "type_var": 2
        }
    },
    {
        "type": "int",
        "id": 1,
        "value": 67
    },
    {
        "type": ".class",
        "name": "class",
        "id": 2,
        "value": "<class 'int'>"
    }
]
image

Updated MemoryViz (0.9.0) SVG

Converted JSON Payload
[
    {
        "type": ".frame",
        "name": "__main__",
        "value": {
            "number_var": 1,
            "type_var": 2
        }
    },
    {
        "type": "int",
        "id": 1,
        "value": 67
    },
    {
        "type": ".class",
        "name": "int",
        "id": 2,
        "value": {}
    }
]
image

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue) X
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📚 Documentation update (change that only updates documentation)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • I have updated the project Changelog (this is required for all changes).
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

  • Note that because the stricter limitation on the MemoryViz Typescript schema in types.ts, we can no longer put just the "name" of a type, such as int, str, or dict (nor the string class <'int'>, for example) in the value attribute of the .class / ClassDrawnEntitySchema drawn entity

    From: https://github.com/david-yz-liu/memory-viz/blob/158bd6db990a6a1bc7d87104e819de0a810bee3b/memory-viz/src/types.ts#L112-L122

    export const ClassDrawnEntitySchema = BaseDrawnEntitySchema.extend({
        type: z.literal(".class"),
        name: z.string('"name" field must be a string').default(""),
        value: z
            .record(
                z.string(),
                ObjectId,
                '"value" field must be a dict with integer or null values'
            )
            .default({}),
    });
    • As a result, I've chosen to put the "name" of the type in the name attribute (top-right box of the drawn entity) instead, although this does leave the value attribute empty, and thus the corresponding box to be empty (see screenshots for more details)
    • It's implemented this way because to my understanding, types should be kept under the .class / ClassDrawnEntitySchema entity in MemoryViz, since in Python, types are classes; if we wanted to put something in the value part of the box, we'd have to set it as something like a string / StringDrawnEntitySchema entity, which could be confusing to users since types are not strings
    • In addition, if we set it as a string entity instead, str would confusingly be written in the top-right box and code like x = int and x = "int" would be hard to distinguish
  • I think the coverage is decreasing because the previous invalid_name_checker.py updates, so they should be unrelated to this PR (although I'm not sure why, if there were coverage issues, Coveralls didn't flag the original PR with the changes in the first place)

@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 26432811267

Coverage decreased (-0.3%) to 90.533%

Details

  • Coverage decreased (-0.3%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 4 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

4 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
packages/python-ta/src/python_ta/checkers/invalid_name_checker.py 4 98.25%

Coverage Stats

Coverage Status
Relevant Lines: 3919
Covered Lines: 3548
Line Coverage: 90.53%
Coverage Strength: 17.57 hits per line

💛 - Coveralls

@a1-su a1-su requested a review from david-yz-liu May 26, 2026 04:57
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