MCPcopy
hub / github.com/fluentpython/example-code-2e / Environment

Class Environment

18-with-match/lispy/py3.10/lis.py:65–74  ·  view source on GitHub ↗

A ChainMap that allows changing an item in-place.

Source from the content-addressed store, hash-verified

63
64# tag::ENV_CLASS[]
65class 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
77def standard_env() -> Environment:

Callers 5

test_evaluate_variableFunction · 0.90
standard_envFunction · 0.70
replFunction · 0.70
__call__Method · 0.70
runFunction · 0.70

Calls

no outgoing calls

Tested by 1

test_evaluate_variableFunction · 0.72