Author vstinner
Recipients eric.snow, gvanrossum, vstinner
Date 2012-03-22.12:35:56
SpamBayes Score 1.16746e-12
Marked as misclassified No
Message-id <1332419759.16.0.326090027041.issue14386@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-03-22 12:35:59vstinnersetrecipients: + vstinner, gvanrossum, eric.snow
2012-03-22 12:35:59vstinnersetmessageid: <1332419759.16.0.326090027041.issue14386@psf.upfronthosting.co.za>
2012-03-22 12:35:58vstinnerlinkissue14386 messages
2012-03-22 12:35:58vstinnercreate