Skip to content

Commit 0771987

Browse files
Add is_empty() to InferenceContext
1 parent 171c48b commit 0771987

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

astroid/context.py

+12
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ def restore_path(self):
152152
yield
153153
self.path = path
154154

155+
def is_empty(self) -> bool:
156+
return (
157+
not self.path
158+
and not self.nodes_inferred
159+
and not self.callcontext
160+
and not self.boundnode
161+
and not self.lookupname
162+
and not self.callcontext
163+
and not self.extra_context
164+
and not self.constraints
165+
)
166+
155167
def __str__(self) -> str:
156168
state = (
157169
f"{field}={pprint.pformat(getattr(self, field), width=80 - len(field))}"

astroid/inference_tip.py

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def _inference_tip_cached(
3535
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Iterator[InferenceResult]:
3636
node = args[0]
3737
context = args[1]
38+
if context.is_empty():
39+
# Fresh, empty contexts will defeat the cache.
40+
context = None
3841
try:
3942
result = _cache[func, node, context]
4043
# If through recursion we end up trying to infer the same

0 commit comments

Comments
 (0)