Skip to content

Commit 7227341

Browse files
change to set
1 parent c1a2a16 commit 7227341

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pytools/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ def hash_unhashable(obj: object) -> Union[object, Tuple[int, str]]:
205205

206206
# Collect objects first to differentiate to outside objects later
207207
for obj in objects:
208-
res[hash_unhashable(obj)] = []
208+
res[hash_unhashable(obj)] = set()
209209

210210
for obj in objects:
211211
refs = gc.get_referents(obj)
212212
obj = hash_unhashable(obj)
213213
for r in refs:
214214
r = hash_unhashable(r)
215215
if r in res or outside_objects:
216-
res.setdefault(obj, []).append(r)
216+
res.setdefault(obj, set()).add(r)
217217

218218
return res
219219

test/test_debug.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ def test_get_object_graph():
5757
a = (1,)
5858
b = (2,)
5959
c = (a, b)
60-
assert get_object_graph([a]) == {(1,): []}
61-
assert get_object_graph([a, b]) == {(1,): [], (2,): []}
62-
assert get_object_graph([a, b, c]) == {((1,), (2,)): [(2,), (1,)], # c: [a, b]
63-
(1,): [], # a: []
64-
(2,): []} # b: []
60+
assert get_object_graph([a]) == {(1,): set()}
61+
assert get_object_graph([a, b]) == {(1,): set(), (2,): set()}
62+
assert get_object_graph([a, b, c]) == {((1,), (2,)): {(2,), (1,)}, # c: [a, b]
63+
(1,): set(), # a: set()
64+
(2,): set()} # b: set()
6565

6666
a = {}
6767
b = {"a": a}
6868
a["b"] = b
6969

7070
assert get_object_graph([a, b]) == {
71-
(id(a), "{'b': {'a': {...}}}"): [(id(b), "{'a': {'b': {...}}}")],
72-
(id(b), "{'a': {'b': {...}}}"): [(id(a), "{'b': {'a': {...}}}")]}
71+
(id(a), "{'b': {'a': {...}}}"): {(id(b), "{'a': {'b': {...}}}")},
72+
(id(b), "{'a': {'b': {...}}}"): {(id(a), "{'b': {'a': {...}}}")}}
7373

7474
b = [42, 4]
7575
a = [1, 2, 3, 4, 5, b]
7676
b.append(a)
7777

7878
assert get_object_graph([a, b]) == {
7979
(id(a), "[1, 2, 3, 4, 5, [42, 4, [...]]]"):
80-
[(id(b), "[42, 4, [1, 2, 3, 4, 5, [...]]]")],
80+
{(id(b), "[42, 4, [1, 2, 3, 4, 5, [...]]]")},
8181
(id(b), "[42, 4, [1, 2, 3, 4, 5, [...]]]"):
82-
[(id(a), "[1, 2, 3, 4, 5, [42, 4, [...]]]")]}
82+
{(id(a), "[1, 2, 3, 4, 5, [42, 4, [...]]]")}}

0 commit comments

Comments
 (0)