Skip to content

Commit a1f8c77

Browse files
committed
Fix: the cache should not be touched outside of overloads
1 parent 665a311 commit a1f8c77

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mypy/checkexpr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def __init__(
360360
self._args_cache: dict[tuple[int, ...], list[Type]] = {}
361361

362362
def reset(self) -> None:
363+
assert self.overload_stack_depth == 0
364+
assert not self._args_cache
363365
self.resolved_type = {}
364366

365367
def visit_name_expr(self, e: NameExpr) -> Type:
@@ -1949,7 +1951,12 @@ def infer_arg_types_in_empty_context(self, args: list[Expression]) -> list[Type]
19491951
In short, we basically recurse on each argument without considering
19501952
in what context the argument was called.
19511953
"""
1952-
can_cache = not any(isinstance(t, TempNode) for t in args)
1954+
# We can only use this hack locally while checking a single nested overloaded
1955+
# call. This saves a lot of rechecking, but is not generally safe. Cache is
1956+
# pruned upon leaving the outermost overload.
1957+
can_cache = self.overload_stack_depth > 0 and not any(
1958+
isinstance(t, TempNode) for t in args
1959+
)
19531960
key = tuple(map(id, args))
19541961
if can_cache and key in self._args_cache:
19551962
return self._args_cache[key]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy