STINNER Victor <victor.stin...@gmail.com> added the comment:

Patch version 2:

 - add tests and documentation
 - dictproxy code moved to dictproxyobject.c
 - dict_proxy replaced with dictproxy in repr(dictproxy)
 - "key in dictproxy" now handles correctly dict subclasses
 - dictproxy constructor raises a TypeError if the argument is not a dict

I added a section "Immutable Mapping" in the doc, this title is maybe wrong 
because a dictproxy is not truly immutable. If the dict referenced by the 
dictproxy is modified, the dictproxy is also modified.

dictproxy implementation supports any mapping, it is not specific to dict. It 
would be interesting any mapping, collections.ChainMap for example. The problem 
is to reject sequence in dictproxy constructor.

The "PyMapping_Check(dict) && !PyMapping_Check(dict)" fails on ChainMap. 
type.__new__(ChainMap) fills tp_as_sequence->sq_item slot is defined because 
ChainMap has a __getitem__ method.

Accepting sequences would be a bad idea because 
dictproxy(sequence)[missing_key] raises IndexError instead of KeyError.

Note: issubclass(collections.ChainMap, collections.abc.Sequence) is False.

----------
Added file: http://bugs.python.org/file24991/dictproxy-2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14386>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to