def __setitem__(self, key, value):
if isinstance(key, toplevels.Name):<EOL><INDENT>if len(key.sub_names) == <NUM_LIT:1>:<EOL><INDENT>name = key.sub_names[<NUM_LIT:0>]<EOL>if name in self:<EOL><INDENT>self[name] = CascadeDict(self[name], value)<EOL><DEDENT>else:<EOL><INDENT>self[name] = value<EOL><DEDENT><DEDENT>elif len(key.sub_names) > <NUM_LIT:1>:<EOL><INDENT>name = key.sub_names[<NUM_LIT:0>]<EOL>rest_of_key = key.drop(<NUM_LIT:1>)<EOL>if name in self:<EOL><INDENT>named_dict = NamedDict()<EOL>named_dict[rest_of_key] = value<EOL>self[name] = CascadeDict(self[name], named_dict)<EOL><DEDENT>else:<EOL><INDENT>self[name] = NamedDict()<EOL>self[name][rest_of_key] = value<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return dict.__setitem__(self, key, value)<EOL><DEDENT>
key can be an Name instance.

When key is a path in the form of an Name instance, all the parents and grandparents of the value are
created along the way as instances of NamedDict. If the parent of the value exists, it is replaced with a
CascadeDict() that cascades the old parent value with a new NamedDict that contains the given child name
and value.