Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/python-ta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions packages/python-ta/src/python_ta/debug/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 7 additions & 26 deletions packages/python-ta/tests/test_debug/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand All @@ -361,7 +359,6 @@ def test_snapshot_to_json_none():
assert json_data == [
{
"type": ".frame",
"id": None,
"name": "func1",
"value": {"test_var": 1},
},
Expand All @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -741,7 +725,6 @@ def test_snapshot_to_json_one_class():

expected_output = [
{
"id": None,
"type": ".frame",
"name": "__main__",
"value": {"one_class_instance": 1},
Expand Down Expand Up @@ -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": {},
},
]

Expand Down Expand Up @@ -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},
Expand Down