From 9fa8e11d2357b0ac4b3a88cf76c5880288714bf2 Mon Sep 17 00:00:00 2001 From: Alan Su Date: Tue, 26 May 2026 00:08:06 -0400 Subject: [PATCH] Update snapshot.py to work with MemoryViz 0.9.0 schema --- packages/python-ta/CHANGELOG.md | 1 + .../python-ta/src/python_ta/debug/snapshot.py | 7 ++-- .../tests/test_debug/test_snapshot.py | 33 ++++--------------- 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/packages/python-ta/CHANGELOG.md b/packages/python-ta/CHANGELOG.md index 3a2c2443a..2d5f65b22 100644 --- a/packages/python-ta/CHANGELOG.md +++ b/packages/python-ta/CHANGELOG.md @@ -17,6 +17,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Make `watchdog` an optional dependency; users can opt in with `pip install python-ta[watchdog]`. This affects runs of `python_ta.check_all` with the `watch` config option set to `True`. - Added `LSPReporter`, a new reporter that outputs lint diagnostics in LSP 3.17-compliant JSON format. - Added suggested fixes for pascal and uppercase names in `invalid_name_checker.py` +- Update `snapshot_to_json` function in `snapshot.py` to handle updated MemoryViz `0.9.0` schema and update version in `snapshot` back to "latest" ### 💫 New checkers diff --git a/packages/python-ta/src/python_ta/debug/snapshot.py b/packages/python-ta/src/python_ta/debug/snapshot.py index 051dccf35..eb3e8923e 100644 --- a/packages/python-ta/src/python_ta/debug/snapshot.py +++ b/packages/python-ta/src/python_ta/debug/snapshot.py @@ -66,7 +66,7 @@ def get_filtered_local_variables( def snapshot( save: bool = False, memory_viz_args: Optional[list[str]] = None, - memory_viz_version: str = "0.7.0", + memory_viz_version: str = "latest", include_frames: Optional[Iterable[str | re.Pattern]] = None, exclude_frames: Optional[Iterable[str | re.Pattern]] = None, exclude_vars: Optional[Iterable[str | re.Pattern]] = None, @@ -216,9 +216,9 @@ def process_value(val: Any) -> int: elif isinstance(val, type): value_entry = { "type": ".class", - "name": "class", + "name": val.__name__, "id": value_id_diagram, - "value": repr(val), + "value": {}, } # Handle user-defined classes elif hasattr(val, "__dict__"): # Check if val is a user-defined class instance @@ -263,7 +263,6 @@ def process_value(val: Any) -> int: json_object_frame = { "type": ".frame", "name": frame_name, - "id": None, "value": frame_variables, } json_data.append(json_object_frame) diff --git a/packages/python-ta/tests/test_debug/test_snapshot.py b/packages/python-ta/tests/test_debug/test_snapshot.py index c6a50759b..df842692a 100644 --- a/packages/python-ta/tests/test_debug/test_snapshot.py +++ b/packages/python-ta/tests/test_debug/test_snapshot.py @@ -335,13 +335,11 @@ def test_snapshot_to_json_primitive(): assert json_data == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_var1a": 1, "test_var2a": 2}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"num": 3, "is_david_cool": 4, "num_alias": 3}, }, @@ -361,7 +359,6 @@ def test_snapshot_to_json_none(): assert json_data == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_var": 1}, }, @@ -385,13 +382,11 @@ def test_snapshot_to_json_lists_primitive_only(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_var1a": 1, "test_var2a": 5}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"projects": 8}, }, @@ -428,13 +423,11 @@ def test_snapshot_to_json_tuples_primitive(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_var1a": 1, "test_var2a": 5}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"projects": 8}, }, @@ -481,13 +474,11 @@ def test_snapshot_to_json_sets_primitive(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_var1a": 1, "test_var2a": 5}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"projects": 8}, }, @@ -519,10 +510,9 @@ def test_snapshot_to_json_dicts_primitive(): json_data_objects = sorted(json_data[2:], key=lambda x: x["id"]) assert json_data_frames == [ - {"type": ".frame", "name": "func1", "id": None, "value": {"var1": 1}}, + {"type": ".frame", "name": "func1", "value": {"var1": 1}}, { "type": ".frame", - "id": None, "name": "__main__", "value": {"var2": 6}, }, @@ -569,13 +559,11 @@ def test_snapshot_to_json_lists_of_dicts(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"test_list1": 1, "test_list2": 8}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"projects": 15}, }, @@ -622,13 +610,11 @@ def test_snapshot_to_json_dicts_of_lists(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"var1": 1, "var2": 5}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"config": 9, "values": 13}, }, @@ -675,13 +661,11 @@ def test_snapshot_to_json_dicts_of_dicts(): assert json_data_frames == [ { "type": ".frame", - "id": None, "name": "func1", "value": {"nested1": 1, "nested2": 6}, }, { "type": ".frame", - "id": None, "name": "__main__", "value": {"configurations": 11}, }, @@ -741,7 +725,6 @@ def test_snapshot_to_json_one_class(): expected_output = [ { - "id": None, "type": ".frame", "name": "__main__", "value": {"one_class_instance": 1}, @@ -773,26 +756,25 @@ def test_snapshot_to_json_type_object(): { "type": ".frame", "name": "__main__", - "id": None, "value": {"t1": 1, "t2": 2, "t3": 3}, }, { "type": ".class", - "name": "class", + "name": "int", "id": 1, - "value": repr(int), + "value": {}, }, { "type": ".class", - "name": "class", + "name": "str", "id": 2, - "value": repr(str), + "value": {}, }, { "type": ".class", - "name": "class", + "name": "OneClass", "id": 3, - "value": repr(OneClass), + "value": {}, }, ] @@ -941,7 +923,6 @@ def test_snapshot_serializes_unserializable_value(): result = func_with_unserializable_objects() assert result == [ { - "id": None, "name": "func_with_unserializable_objects", "type": ".frame", "value": {"var": 1},