Skip to content

Commit ac3e240

Browse files
authored
Add internal flag to disable expression cache (#19569)
1 parent 2ce5795 commit ac3e240

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6030,8 +6030,10 @@ def accept(
60306030
# We cannot use cache inside lambdas, because they skip immediate type
60316031
# context, and use enclosing one, see infer_lambda_type_using_context().
60326032
# TODO: consider using cache for more expression kinds.
6033-
elif isinstance(node, (CallExpr, ListExpr, TupleExpr, DictExpr, OpExpr)) and not (
6034-
self.in_lambda_expr or self.chk.current_node_deferred
6033+
elif (
6034+
isinstance(node, (CallExpr, ListExpr, TupleExpr, DictExpr, OpExpr))
6035+
and not (self.in_lambda_expr or self.chk.current_node_deferred)
6036+
and not self.chk.options.disable_expression_cache
60356037
):
60366038
if (node, type_context) in self.expr_cache:
60376039
binder_version, typ, messages, type_map = self.expr_cache[(node, type_context)]

mypy/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,15 @@ def add_invertible_flag(
10901090
help="Use a custom typing module",
10911091
)
10921092
internals_group.add_argument(
1093-
"--old-type-inference",
1094-
action="store_true",
1095-
help="Disable new experimental type inference algorithm",
1093+
"--old-type-inference", action="store_true", help=argparse.SUPPRESS
10961094
)
10971095
# Deprecated reverse variant of the above.
10981096
internals_group.add_argument(
10991097
"--new-type-inference", action="store_true", help=argparse.SUPPRESS
11001098
)
1099+
internals_group.add_argument(
1100+
"--disable-expression-cache", action="store_true", help=argparse.SUPPRESS
1101+
)
11011102
parser.add_argument(
11021103
"--enable-incomplete-feature",
11031104
action="append",

mypy/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ def __init__(self) -> None:
395395
self.old_type_inference = False
396396
# Deprecated reverse version of the above, do not use.
397397
self.new_type_inference = False
398+
# Disable expression cache (for debugging).
399+
self.disable_expression_cache = False
398400
# Export line-level, limited, fine-grained dependency information in cache data
399401
# (undocumented feature).
400402
self.export_ref_info = False

0 commit comments

Comments
 (0)