diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index bec34eef4983..740efb0d2ee4 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -6030,8 +6030,10 @@ def accept( # We cannot use cache inside lambdas, because they skip immediate type # context, and use enclosing one, see infer_lambda_type_using_context(). # TODO: consider using cache for more expression kinds. - elif isinstance(node, (CallExpr, ListExpr, TupleExpr, DictExpr, OpExpr)) and not ( - self.in_lambda_expr or self.chk.current_node_deferred + elif ( + isinstance(node, (CallExpr, ListExpr, TupleExpr, DictExpr, OpExpr)) + and not (self.in_lambda_expr or self.chk.current_node_deferred) + and not self.chk.options.disable_expression_cache ): if (node, type_context) in self.expr_cache: binder_version, typ, messages, type_map = self.expr_cache[(node, type_context)] diff --git a/mypy/main.py b/mypy/main.py index a407a88d3ac1..6e307ab25c48 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1090,14 +1090,15 @@ def add_invertible_flag( help="Use a custom typing module", ) internals_group.add_argument( - "--old-type-inference", - action="store_true", - help="Disable new experimental type inference algorithm", + "--old-type-inference", action="store_true", help=argparse.SUPPRESS ) # Deprecated reverse variant of the above. internals_group.add_argument( "--new-type-inference", action="store_true", help=argparse.SUPPRESS ) + internals_group.add_argument( + "--disable-expression-cache", action="store_true", help=argparse.SUPPRESS + ) parser.add_argument( "--enable-incomplete-feature", action="append", diff --git a/mypy/options.py b/mypy/options.py index 4a89ef529c07..be61059be5c6 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -395,6 +395,8 @@ def __init__(self) -> None: self.old_type_inference = False # Deprecated reverse version of the above, do not use. self.new_type_inference = False + # Disable expression cache (for debugging). + self.disable_expression_cache = False # Export line-level, limited, fine-grained dependency information in cache data # (undocumented feature). self.export_ref_info = False