[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee:  - rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Can you write-up a patch with tests and a doc change?

--
stage:  - needs patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Vinay Sajip

Changes by Vinay Sajip vinay_sa...@yahoo.co.uk:


--
hgrepos: +171

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Vinay Sajip

Changes by Vinay Sajip vinay_sa...@yahoo.co.uk:


--
keywords: +patch
Added file: http://bugs.python.org/file28694/951243de359a.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Vinay Sajip

Vinay Sajip added the comment:

 Can you write-up a patch with tests and a doc change?

Done.

--
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Put a *versionchanged* tag in the doc entry and this is ready to apply.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee: rhettinger - vinay.sajip

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Also, please change the variable name from *amap* to either *m* or *mapping*.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset c0ddae67f4df by Vinay Sajip in branch 'default':
Closes #16613: Added optional mapping argument to ChainMap.new_child.
http://hg.python.org/cpython/rev/c0ddae67f4df

--
nosy: +python-dev
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-10 Thread Walter Dörwald

Walter Dörwald added the comment:

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'.

--
nosy: +doerwalter

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-10 Thread Vinay Sajip

Vinay Sajip added the comment:

 d if d is not None else {}

Your intention makes sense, though I would prefer to write it as:

if d is None:
d = {}
return self.__class__(d, *self.maps)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2013-01-07 Thread R. David Murray

R. David Murray added the comment:

I agree that this would be useful.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16613] ChainMap.new_child could use improvement

2012-12-05 Thread Vinay Sajip

New submission from Vinay Sajip:

ChainMap.new_child could IMO be improved through allowing an optional dict to 
be passed, which is used to create the child. The use case is that you 
sometimes need to temporarily push a new non-empty mapping in front of an 
existing chain. This could be achieved by changing new_child to the following, 
which is backwards-compatible:

def new_child(self, d=None):
'New ChainMap with a new dict followed by all previous maps.'
return self.__class__(d or {}, *self.maps)

--
components: Library (Lib)
messages: 176974
nosy: rhettinger, vinay.sajip
priority: normal
severity: normal
status: open
title: ChainMap.new_child could use improvement
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16613
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com