def chainmap_context_factory(parent_context=None):
"""
A ``ChainMap`` context, to avoid copying any data
and yet preserve strict one-way inheritance
(just like with dict copying)
"""
if parent_context is None:
# initial context
return ChainMap()
else:
# inherit context
if not isinstance(parent_context, ChainMap):
# if a dict context was previously used, then convert
# (without modifying the original dict)
parent_context = ChainMap(parent_context)
return parent_context.new_child()
评论列表
文章目录