mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] gh-125608: Trigger dictionary watchers when inline values change (GH-125611) (GH-125982)
Dictionary watchers on an object's attributes dictionary
(`object.__dict__`) were not triggered when the managed dictionary used
the object's inline values.
(cherry picked from commit 5989eb7446
)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
dba992b03b
commit
7b46ae92ad
3 changed files with 35 additions and 6 deletions
|
@ -96,6 +96,23 @@ class TestDictWatchers(unittest.TestCase):
|
|||
del d
|
||||
self.assert_events(["dealloc"])
|
||||
|
||||
def test_object_dict(self):
|
||||
class MyObj: pass
|
||||
o = MyObj()
|
||||
|
||||
with self.watcher() as wid:
|
||||
self.watch(wid, o.__dict__)
|
||||
o.foo = "bar"
|
||||
o.foo = "baz"
|
||||
del o.foo
|
||||
self.assert_events(["new:foo:bar", "mod:foo:baz", "del:foo"])
|
||||
|
||||
with self.watcher() as wid:
|
||||
self.watch(wid, o.__dict__)
|
||||
for _ in range(100):
|
||||
o.foo = "bar"
|
||||
self.assert_events(["new:foo:bar"] + ["mod:foo:bar"] * 99)
|
||||
|
||||
def test_unwatch(self):
|
||||
d = {}
|
||||
with self.watcher() as wid:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue