diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-05-14 20:12:02 -0400 |
---|---|---|
committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-05-15 10:09:17 -0400 |
commit | 8d026e0c61cf7f445ba9f8110e8e120df0940029 (patch) | |
tree | 618d361d9daebd9ef3ddfc877731f13d732cc636 | |
parent | 93e3703c4817ef28b156ae159b2030fdc4086191 (diff) | |
download | astroid-git-8d026e0c61cf7f445ba9f8110e8e120df0940029.tar.gz |
Add `InferenceContext.is_empty()`
-rw-r--r-- | astroid/context.py | 12 | ||||
-rw-r--r-- | astroid/inference_tip.py | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/astroid/context.py b/astroid/context.py index a151ca62..cccc81c0 100644 --- a/astroid/context.py +++ b/astroid/context.py @@ -140,6 +140,18 @@ class InferenceContext: yield self.path = path + def is_empty(self) -> bool: + return ( + not self.path + and not self.nodes_inferred + and not self.callcontext + and not self.boundnode + and not self.lookupname + and not self.callcontext + and not self.extra_context + and not self.constraints + ) + def __str__(self) -> str: state = ( f"{field}={pprint.pformat(getattr(self, field), width=80 - len(field))}" diff --git a/astroid/inference_tip.py b/astroid/inference_tip.py index 94c914e6..2e472437 100644 --- a/astroid/inference_tip.py +++ b/astroid/inference_tip.py @@ -46,6 +46,9 @@ def _inference_tip_cached(func: InferFn[_NodesT]) -> InferFn[_NodesT]: # func + node we raise here. _CURRENTLY_INFERRING.remove(partial_cache_key) raise UseInferenceDefault + if context is not None and context.is_empty(): + # Fresh, empty contexts will defeat the cache. + context = None try: yield from _cache[func, node, context] return |