[Python-ideas] History on proposals for Macros?

Steven D'Aprano steve at pearwood.info
Mon Mar 30 13:11:11 CEST 2015


On Mon, Mar 30, 2015 at 12:03:47AM -0700, Andrew Barnert wrote:
> On Mar 29, 2015, at 21:12, Ron Adam <ron3200 at gmail.com> wrote:
[snip stuff about dynamic scoping]

Raymond Hettinger's ChainMap (now also in the std lib) may possibly be 
used to emulate different scoping rules, including dynamic.

http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/

http://code.activestate.com/recipes/305268-chained-map-lookups/

If you can build a function object with __globals__ set to a chained 
map, you may be able to accomplish most of what you are discussing. 

By memory, __globals__ needs to be a dict, so you have to use a dict 
subclass, something like this:

class Context(ChainMap, dict): pass


-- 
Steve


More information about the Python-ideas mailing list