Skip to content

Commit 4137875

Browse files
authored
detect loops in transitive_get
1 parent bffa736 commit 4137875

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

unification/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ def transitive_get(key, d):
1515
>>> transitive_get(1, d)
1616
4
1717
"""
18-
with suppress(TypeError):
19-
while key in d:
20-
key = d[key]
18+
for _ in range(len(d)):
19+
key = d[key]
20+
21+
with suppress(TypeError):
22+
if key in d:
23+
continue
24+
break
25+
else:
26+
raise RecursionError('dict contains a loop')
27+
2128
return key
2229

2330

0 commit comments

Comments
 (0)