Skip to content

Commit

Permalink
- debugger.py: use Watches.remove and .add to update an edited expres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
Kevin-Prichard committed Oct 5, 2024
1 parent 4cd94fe commit 921dbb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,11 @@ def edit_inspector_detail(w, size, key):
iinfo.access_level = "all"

if var.watch_expr is not None:
var.watch_expr.expression = watch_edit.get_edit_text()
# Remove old expression and add new one, to avoid rehashing
Watches.remove(var.watch_expr)
var.watch_expr = WatchExpression(
watch_edit.get_edit_text())
Watches.add(var.watch_expr)

elif result == "del":
# Remove saved expression
Expand Down
8 changes: 8 additions & 0 deletions pudb/test/test_var_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from unittest.mock import patch, mock_open

import pytest

from pudb.var_view import (
STRINGIFIERS,
BasicValueWalker,
Expand Down Expand Up @@ -473,6 +475,12 @@ def test_set(self):
test_set2.add(WatchExpression("a"))
self.assertEqual(test_set1, test_set2)

def test_immutability(self):
Watches.clear()
we_a = WatchExpression("a")
with pytest.raises(AttributeError):
we_a.expression = "b"


class WatchesTests(unittest.TestCase):
"""
Expand Down

0 comments on commit 921dbb0

Please sign in to comment.