Issue 17660: mock.patch could whitelist builtins to not need create=True (original) (raw)

Issue17660

Created on 2013-04-08 10:48 by michael.foord, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17660.patch kushal.das,2013-04-08 13:26 initial patch review
issue17660_v3.patch kushal.das,2014-04-14 17:07 Updated patch with builtins module. review
Messages (11)
msg186290 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-04-08 10:48
When patching builtin names (e.g. open) in a specific namespace you need to specify "create=True" or patch will refuse to create a name that doesn't exist. patch could whitelist the builtin names, when the patch target is a module object, to not require the "create=True".
msg186291 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2013-04-08 10:52
Working on this.
msg186301 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2013-04-08 13:26
Initial patchset along with documentation and tests update.
msg186323 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-08 18:17
To be honest this proposal sounds like a quirk more than a feature to me. If you only special-case builtins, people will have to remember that special case and it will make the API more complicated.
msg186347 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-04-08 21:02
I don't think that's a particular issue. In general you only need to use "create=True" if a name is *not* available in a namespace. Builtin names are odd in that you can use them in a namespace even though they don't exist there - so you have to *remember* to use "create=True" even though the name *is* available. So this issue is about fixing that quirk.
msg215917 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-04-11 06:21
Reviewed on Rietveld.
msg216113 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2014-04-14 17:07
Updated patch with builtins module.
msg216201 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-04-14 20:25
New changeset e457de60028c by Michael Foord in branch 'default': Closes issue 17660. You no longer need to explicitly pass create=True when patching builtin names. http://hg.python.org/cpython/rev/e457de60028c
msg216360 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-04-15 18:52
+ .. note:: I think using a note directive is not necessary here. Also it looks a bit ugly :) https://dl.dropboxusercontent.com/u/166024/issue17660.png + .. versionchanged:: 3.5 + If you are patching builtins in a module then you don't + need to pass `create=True`, it will be added by default.
msg216364 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-15 19:26
Personally I don't think it looks ugly and that it is a point worth calling out. Other opinions welcomed.
msg216366 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-04-15 19:28
I noticed this in the commit; I don’t think the rendered output is really ugly, but the markup does look strange, as it’s two nested note(-like) directives.
History
Date User Action Args
2022-04-11 14:57:44 admin set github: 61860
2014-04-15 19:28:37 eric.araujo set messages: +
2014-04-15 19:26:09 michael.foord set messages: +
2014-04-15 18:52:49 berker.peksag set nosy: + berker.peksagmessages: +
2014-04-14 20:25:31 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: patch review -> resolved
2014-04-14 17:53:49 eric.araujo set versions: + Python 3.5, - Python 3.4
2014-04-14 17:07:41 kushal.das set files: + issue17660_v3.patchmessages: + versions: + Python 3.4, - Python 3.5
2014-04-11 06:21:00 eric.araujo set versions: + Python 3.5, - Python 3.4nosy: + eric.araujomessages: + stage: needs patch -> patch review
2013-04-08 21:02:08 michael.foord set messages: +
2013-04-08 18:17:07 pitrou set nosy: + pitroumessages: +
2013-04-08 13:26:19 kushal.das set files: + issue17660.patchkeywords: + patchmessages: +
2013-04-08 10:52:24 kushal.das set nosy: + kushal.dasmessages: +
2013-04-08 10:48:09 michael.foord create