| 124 | self.assertFalse(hasattr(a, "b")) |
| 125 | |
| 126 | def test_no_collateral_damage(self): |
| 127 | # A and B are immutable but not related. The magic that lets |
| 128 | # us write to immutable things while initializing B should not let |
| 129 | # B mess with A. |
| 130 | |
| 131 | class A: |
| 132 | def __init__(self, a): |
| 133 | self.a = a |
| 134 | |
| 135 | A = self.immutable_module.immutable(A) |
| 136 | |
| 137 | class B: |
| 138 | def __init__(self, a, b): |
| 139 | self.b = a.a + b |
| 140 | # rudely attempt to mutate innocent immutable bystander 'a' |
| 141 | a.a = 1000 |
| 142 | |
| 143 | B = self.immutable_module.immutable(B) |
| 144 | |
| 145 | a = A(10) |
| 146 | self.assertEqual(a.a, 10) |
| 147 | with self.assertRaises(TypeError): |
| 148 | B(a, 20) |
| 149 | self.assertEqual(a.a, 10) |