Skip to content

Commit f298714

Browse files
committed
fix: no nested
1 parent fd075dd commit f298714

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

mypyc/irbuild/expression.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff 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

mypyc/test-data/run-dicts.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,23 @@ from native import (
472472
test_mutation_independence()
473473
test_ineligible_not_folded()
474474
test_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

0 commit comments

Comments
 (0)