Skip to content

Commit e6f449c

Browse files
Add InferenceContext.is_empty()
1 parent 1b9b4f7 commit e6f449c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

astroid/context.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ def restore_path(self) -> Iterator[None]:
140140
yield
141141
self.path = path
142142

143+
def is_empty(self) -> bool:
144+
return (
145+
not self.path
146+
and not self.nodes_inferred
147+
and not self.callcontext
148+
and not self.boundnode
149+
and not self.lookupname
150+
and not self.callcontext
151+
and not self.extra_context
152+
and not self.constraints
153+
)
154+
143155
def __str__(self) -> str:
144156
state = (
145157
f"{field}={pprint.pformat(getattr(self, field), width=80 - len(field))}"

astroid/inference_tip.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def inner(
4646
# func + node we raise here.
4747
_CURRENTLY_INFERRING.remove(partial_cache_key)
4848
raise UseInferenceDefault
49+
if context is not None and context.is_empty():
50+
# Fresh, empty contexts will defeat the cache.
51+
context = None
4952
try:
5053
yield from _cache[func, node, context]
5154
return

0 commit comments

Comments
 (0)