Issue 21991: The new email API should use MappingProxyType instead of returning new dicts. (original) (raw)

Created on 2014-07-16 14:29 by r.david.murray, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue21991.patch matrixise,2014-10-15 09:54 review
Messages (18)
msg223211 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-07-16 14:29
There are a few places in the new email API where dicts are returned containing what is conceptually static information. Currently this is done by returning a copy of the dict from the object, so that user code modifying the dict won't break the object invariants. It would be better to change these to MappingProxyType objects instead, before the API moves out of provisional status. This issue is mostly a note to myself, since I'm the most likely to be able to figure out which places in the code need changing, but if anyone else wants to look at it feel free, since it will probably be a while before I get to it.
msg224797 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-08-05 03:07
Hi David, I can take this on as I am learning the email api currently.
msg229251 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-13 16:37
David, do you have an example, I am at the CPython sprint in Dublin, and I think I can work on this issue. Thanks
msg229254 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-13 17:04
The principle example is the 'params' dictionary in headerregistry. Currently it gets recreated every time you access that attribute. You can *apparently* change it, but that has no real effect. Probably the computed value should be cached the first time the attribute is accessed, and a MappingProxy over the cached value returned.
msg229299 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-14 15:10
Hi David, I didn't find an other example of a copy(dict), the rest is just some lists. If you have an other example in the email library, I will agree to provide an other patch.
msg229300 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-14 15:12
In fact, I am really dubious with my patch because this one is really small and I think there is a missing part somewhere because the description of this issue takes 4 lines and the patch only 2.
msg229306 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-14 15:49
Here is the new version of this patch with a test.
msg229321 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-14 17:31
No, it looks fine. This issue was mostly a reminder to myself. Thanks for the patch. The other place I thought there might be some instances of this was in _header_value_parser, but I don't see any on a quick scan. So this may be it.
msg229413 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-15 08:34
Tell me if you will review this patch and maybe accept it ;-) In fact I checked all the return keywords in the email library and I didn't find any other copy of a dict. This is the reason why I am dubious about my patch ;-)
msg229425 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-15 09:54
New version of the patch
msg229426 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-15 09:54
sorry, but how to update a patch without losing the rietveld review? Is there a documentation about that? Thanks. Stephane
msg229435 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-15 11:50
> sorry, but how to update a patch without losing the rietveld review? I see 3 patch sets at: http://bugs.python.org/review/21991/ No review is lost when you remove a patch. But it's better to attach a new patch with a different name. I like the name pattern: name.patch, name-2.patch, name-3.patch, etc. It's easier to refer to a patch when it has a unique name.
msg229436 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-15 11:51
.patch looks good to me. I didn't check if more methos should be modified. David knows that better than me :-)
msg229442 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-15 13:10
Personally I would test that the returned object is read only, rather than checking for MappingProxyType explicitly, but you can argue either way as being better :) As for other occurrences, I must have been either misremembering, or I refactored the other occurrences out of existence earlier. Yes I will apply this.
msg229452 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-15 14:26
> Personally I would test that the returned object is read only I agree: write a short helper to check that modifying the dict fails.
msg229616 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-17 23:33
New changeset fea3ddcaf652 by R David Murray in branch '3.4': #21991: make headerregistry params property MappingProxyType. https://hg.python.org/cpython/rev/fea3ddcaf652 New changeset 5beb1ea76f36 by R David Murray in branch 'default': Merge: #21991: make headerregistry params property MappingProxyType. https://hg.python.org/cpython/rev/5beb1ea76f36
msg229617 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-17 23:34
Thanks, Stéphane. I committed the fix with a modified test.
msg229636 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-18 08:24
Thanks David,
History
Date User Action Args
2022-04-11 14:58:06 admin set github: 66190
2014-10-18 08:24:18 matrixise set messages: +
2014-10-17 23:34:23 r.david.murray set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2014-10-17 23:33:02 python-dev set nosy: + python-devmessages: +
2014-10-15 14:26:33 vstinner set messages: +
2014-10-15 13:10:24 r.david.murray set messages: + stage: patch review -> commit review
2014-10-15 11:51:21 vstinner set messages: +
2014-10-15 11:50:37 vstinner set nosy: + vstinnermessages: +
2014-10-15 09:54:44 matrixise set messages: +
2014-10-15 09:54:08 matrixise set files: + issue21991.patchmessages: +
2014-10-15 09:53:31 matrixise set files: - issue21991.patch
2014-10-15 09:28:22 berker.peksag set stage: needs patch -> patch review
2014-10-15 08:34:01 matrixise set messages: +
2014-10-14 17:31:24 r.david.murray set messages: +
2014-10-14 15:49:48 matrixise set files: + issue21991.patchmessages: +
2014-10-14 15:49:13 matrixise set files: - issue21991.patch
2014-10-14 15:12:34 matrixise set messages: +
2014-10-14 15:10:40 matrixise set files: + issue21991.patchkeywords: + patchmessages: +
2014-10-13 17:04:04 r.david.murray set messages: +
2014-10-13 16:37:30 matrixise set nosy: + matrixisemessages: +
2014-09-26 00:07:20 saikrishna17394 set nosy: + saikrishna17394
2014-08-05 03:42:17 Lita.Cho set nosy: + jesstess
2014-08-05 03:07:26 Lita.Cho set nosy: + Lita.Chomessages: +
2014-07-16 14:29:58 r.david.murray create