Message156550
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. |
|
Date |
User |
Action |
Args |
2012-03-22 12:35:59 | vstinner | set | recipients:
+ vstinner, gvanrossum, eric.snow |
2012-03-22 12:35:59 | vstinner | set | messageid: <1332419759.16.0.326090027041.issue14386@psf.upfronthosting.co.za> |
2012-03-22 12:35:58 | vstinner | link | issue14386 messages |
2012-03-22 12:35:58 | vstinner | create | |
|