Skip to content

Commit 29fcf11

Browse files
authored
Merge pull request #553 from jitseniesen/commbase-bug
PR: Fix bug when converting JSON to StackSummary
2 parents afd6216 + a6caaaf commit 29fcf11

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

spyder_kernels/comms/commbase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def stacksummary_to_json(stack):
8181
]
8282

8383

84-
def staksummary_from_json(stack):
84+
def stacksummary_from_json(stack):
8585
"""StackSummary from json."""
86-
traceback.StackSummary.from_list([
86+
return traceback.StackSummary.from_list([
8787
(
8888
frame["filename"],
8989
frame["lineno"],
@@ -127,7 +127,7 @@ def from_json(cls, json_data):
127127
instance.error = instance.etype(*json_data["args"])
128128
if json_data["error_name"]:
129129
instance.error.name = json_data["error_name"]
130-
instance.tb = staksummary_from_json(json_data["tb"])
130+
instance.tb = stacksummary_from_json(json_data["tb"])
131131
return instance
132132

133133
def raise_error(self):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# -----------------------------------------------------------------------------
3+
# Copyright (c) 2025- Spyder Kernels Contributors
4+
#
5+
# Licensed under the terms of the MIT License
6+
# (see spyder_kernels/__init__.py for details)
7+
# -----------------------------------------------------------------------------
8+
9+
"""
10+
Tests for commbase.py
11+
"""
12+
13+
# Local imports
14+
from spyder_kernels.comms.commbase import (
15+
stacksummary_from_json,
16+
stacksummary_to_json,
17+
)
18+
19+
20+
def test_stacksummary_roundtrip():
21+
"""
22+
Test that roundtripping a JSON representation of a StackSummary works.
23+
"""
24+
json = [
25+
{"filename": "f1", "lineno": 42, "name": "n1", "line": "l1"},
26+
{"filename": "f2", "lineno": 42, "name": "n2", "line": "l2"},
27+
]
28+
stacksummary = stacksummary_from_json(json)
29+
assert stacksummary_to_json(stacksummary) == json

0 commit comments

Comments
 (0)