Skip to content

Commit

Permalink
Unwind-protect changes to e.visited using a finally block
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Aug 21, 2019
1 parent 9ddd466 commit 8bb8fd9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions unpythonic/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,22 @@ def f_fix(*args, **kwargs):
value, e.cache[me] = None, bottom(f_fix.__name__, *args, **kwargs)
count = 0
while count < n and value != e.cache[me]:
e.visited.add(me)
value, e.cache[me] = e.cache[me], unwrap(f(*args, **kwargs))
e.visited.clear()
try:
e.visited.add(me)
value, e.cache[me] = e.cache[me], unwrap(f(*args, **kwargs))
finally:
e.visited.clear()
count += 1
return value
if me in e.visited:
# return e.cache.get(me, bottom(f_fix.__name__, *args)
# same effect, except don't compute bottom again if we don't need to.
return e.cache[me] if me in e.cache else bottom(f_fix.__name__, *args, **kwargs)
e.visited.add(me)
value = e.cache[me] = unwrap(f(*args, **kwargs))
e.visited.remove(me)
try:
e.visited.add(me)
value = e.cache[me] = unwrap(f(*args, **kwargs))
finally:
e.visited.remove(me)
return value
f_fix.entrypoint = f # just for information
return f_fix
Expand Down

0 comments on commit 8bb8fd9

Please sign in to comment.