|
233 | 233 | "builtins.memoryview", |
234 | 234 | } |
235 | 235 |
|
| 236 | +POISON_KEY: Final = (-1,) |
| 237 | + |
236 | 238 |
|
237 | 239 | class TooManyUnions(Exception): |
238 | 240 | """Indicates that we need to stop splitting unions in an attempt |
@@ -1954,8 +1956,10 @@ def infer_arg_types_in_empty_context(self, args: list[Expression]) -> list[Type] |
1954 | 1956 | # We can only use this hack locally while checking a single nested overloaded |
1955 | 1957 | # call. This saves a lot of rechecking, but is not generally safe. Cache is |
1956 | 1958 | # 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 | + can_cache = ( |
| 1960 | + self.overload_stack_depth > 0 |
| 1961 | + and POISON_KEY not in self._args_cache |
| 1962 | + and not any(isinstance(t, TempNode) for t in args) |
1959 | 1963 | ) |
1960 | 1964 | key = tuple(map(id, args)) |
1961 | 1965 | if can_cache and key in self._args_cache: |
@@ -5426,6 +5430,9 @@ def find_typeddict_context( |
5426 | 5430 |
|
5427 | 5431 | def visit_lambda_expr(self, e: LambdaExpr) -> Type: |
5428 | 5432 | """Type check lambda expression.""" |
| 5433 | + if self.overload_stack_depth > 0: |
| 5434 | + # Poison cache when we encounter lambdas - it isn't safe to cache their types. |
| 5435 | + self._args_cache[POISON_KEY] = [] |
5429 | 5436 | self.chk.check_default_args(e, body_is_trivial=False) |
5430 | 5437 | inferred_type, type_override = self.infer_lambda_type_using_context(e) |
5431 | 5438 | if not inferred_type: |
|
0 commit comments