summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-05-14 19:46:50 -0400
committerJacob Walls <jacobtylerwalls@gmail.com>2023-05-15 10:09:17 -0400
commit93e3703c4817ef28b156ae159b2030fdc4086191 (patch)
tree898cadce2bf163fae3fb2bada4601c51f5044e45
parent835de848ac7cf51525d714f2f6ed07d789e09c54 (diff)
downloadastroid-git-93e3703c4817ef28b156ae159b2030fdc4086191.tar.gz
Remove cache entries in all exit paths
Follow-up to 0740a0dd5e9cb48bb1a400aded498e4db1fcfca9.
-rw-r--r--astroid/inference_tip.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/astroid/inference_tip.py b/astroid/inference_tip.py
index 44a7fcf1..94c914e6 100644
--- a/astroid/inference_tip.py
+++ b/astroid/inference_tip.py
@@ -44,6 +44,7 @@ def _inference_tip_cached(func: InferFn[_NodesT]) -> InferFn[_NodesT]:
if partial_cache_key in _CURRENTLY_INFERRING:
# If through recursion we end up trying to infer the same
# func + node we raise here.
+ _CURRENTLY_INFERRING.remove(partial_cache_key)
raise UseInferenceDefault
try:
yield from _cache[func, node, context]
@@ -55,9 +56,15 @@ def _inference_tip_cached(func: InferFn[_NodesT]) -> InferFn[_NodesT]:
# with slightly different contexts while still passing the simple
# test cases included with this commit.
_CURRENTLY_INFERRING.add(partial_cache_key)
- result = _cache[func, node, context] = list(func(node, context, **kwargs))
- # Remove recursion guard.
- _CURRENTLY_INFERRING.remove(partial_cache_key)
+ try:
+ # May raise UseInferenceDefault
+ result = _cache[func, node, context] = list(func(node, context, **kwargs))
+ finally:
+ # Remove recursion guard.
+ try:
+ _CURRENTLY_INFERRING.remove(partial_cache_key)
+ except KeyError:
+ pass # Recursion may beat us to the punch.
yield from result