diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-05-14 20:12:02 -0400 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2023-05-14 21:53:09 -0400 |
| commit | c807c03c48aea8e458a7db3df7f7b35e1cdffc6b (patch) | |
| tree | 618d361d9daebd9ef3ddfc877731f13d732cc636 | |
| parent | 6bdd92d1006ae73bd5747d7c3714e10de81f1818 (diff) | |
| download | astroid-git-c807c03c48aea8e458a7db3df7f7b35e1cdffc6b.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 |
