File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -1035,15 +1035,7 @@ def dict_literal_values(
10351035 # Recursively staticize dict values
10361036 value = constant_fold_expr (builder , value_expr )
10371037 if value is None :
1038- # Try to staticize nested dicts
1039- if isinstance (value_expr , DictExpr ):
1040- nested = dict_literal_values (builder , value_expr .items , value_expr .line )
1041- if nested is not None :
1042- value = nested
1043- else :
1044- return None
1045- else :
1046- return None
1038+ return None
10471039 result [key ] = value
10481040
10491041 return result or None
Original file line number Diff line number Diff line change @@ -472,3 +472,23 @@ from native import (
472472test_mutation_independence()
473473test_ineligible_not_folded()
474474test_eligible_folded()
475+
476+ [case testDictLiteralIsImmutable]
477+ def get_flat():
478+ return {"x": 1, "y": 2}
479+ def get_nested():
480+ return {"a": {"b": 1}}
481+ def test_shallow_mutation_independence():
482+ d1 = get_flat()
483+ d2 = get_flat()
484+ d1["x"] = 99
485+ assert d2["x"] == 1
486+ d2["y"] = 42
487+ assert d1["y"] == 2
488+ def test_deep_mutation_independence():
489+ d1 = get_nested()
490+ d2 = get_nested()
491+ d1["a"]["b"] = 99
492+ assert d2["a"]["b"] == 1
493+ d2["a"]["b"] = 42
494+ assert d1["a"]["b"] == 99
You can’t perform that action at this time.
0 commit comments