This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 vstinner
收信人 eric.snow, gvanrossum, vstinner
日期 2012-03-22.12:35:56
SpamBayes Score 1.167455e-12
Marked as misclassified
Message-id <1332419759.16.0.326090027041.issue14386@psf.upfronthosting.co.za>
In-reply-to
内容
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.
历史
日期 用户 动作 参数
2012-03-22 12:35:59vstinner修改recipients: + vstinner, gvanrossum, eric.snow
2012-03-22 12:35:59vstinner修改messageid: <1332419759.16.0.326090027041.issue14386@psf.upfronthosting.co.za>
2012-03-22 12:35:58vstinner链接issue14386 messages
2012-03-22 12:35:58vstinner创建