Skip to content

Commit

Permalink
Add is_empty() to InferenceContext
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Apr 30, 2023
1 parent 171c48b commit 0771987
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions astroid/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def restore_path(self):
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))}"
Expand Down
3 changes: 3 additions & 0 deletions astroid/inference_tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def _inference_tip_cached(
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Iterator[InferenceResult]:
node = args[0]
context = args[1]
if context.is_empty():
# Fresh, empty contexts will defeat the cache.
context = None
try:
result = _cache[func, node, context]
# If through recursion we end up trying to infer the same
Expand Down

0 comments on commit 0771987

Please sign in to comment.