A ChainMap that allows changing an item in-place.
| 63 | |
| 64 | # tag::ENV_CLASS[] |
| 65 | class Environment(ChainMap[Symbol, Any]): |
| 66 | "A ChainMap that allows changing an item in-place." |
| 67 | |
| 68 | def change(self, key: Symbol, value: Any) -> None: |
| 69 | "Find where key is defined and change the value there." |
| 70 | for map in self.maps: |
| 71 | if key in map: |
| 72 | map[key] = value # type: ignore[index] |
| 73 | return |
| 74 | raise KeyError(key) |
| 75 | # end::ENV_CLASS[] |
| 76 | |
| 77 | def standard_env() -> Environment: |
no outgoing calls