Author doerwalter
Recipients doerwalter, r.david.murray, rhettinger, vinay.sajip
Date 2013-01-10.14:36:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1357828580.69.0.115357446947.issue16613@psf.upfronthosting.co.za>
In-reply-to
Content
I'd like to have this feature too. However the code should use

   d if d is not None else {}

instead of

   d or {}

For example I might want to use a subclass of dict (lowerdict) that converts all keys to lowercase. When I use an empty lowerdict in new_child(), new_child() would silently use a normal dict instead:

   class lowerdict(dict):
       def __getitem__(self, key):
           return dict.__getitem__(
               self,
               key.lower() if isinstance(key, str) else key
           )
   
   import collections
   
   cm = collections.ChainMap(lowerdict(), lowerdict())
   
   cm2 = cm.new_child(lowerdict())
   
   print(type(cm2.maps[0]))

This would print <class 'dict'>.
History
Date User Action Args
2013-01-10 14:36:20doerwaltersetrecipients: + doerwalter, rhettinger, vinay.sajip, r.david.murray
2013-01-10 14:36:20doerwaltersetmessageid: <1357828580.69.0.115357446947.issue16613@psf.upfronthosting.co.za>
2013-01-10 14:36:20doerwalterlinkissue16613 messages
2013-01-10 14:36:19doerwaltercreate