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.

classification
Title: mock.patch could whitelist builtins to not need create=True
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: berker.peksag, eric.araujo, kushal.das, michael.foord, pitrou, python-dev
Priority: normal Keywords: easy, patch

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:44adminsetgithub: 61860
2014-04-15 19:28:37eric.araujosetmessages: + msg216366
2014-04-15 19:26:09michael.foordsetmessages: + msg216364
2014-04-15 18:52:49berker.peksagsetnosy: + berker.peksag
messages: + msg216360
2014-04-14 20:25:31python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg216201

resolution: fixed
stage: patch review -> resolved
2014-04-14 17:53:49eric.araujosetversions: + Python 3.5, - Python 3.4
2014-04-14 17:07:41kushal.dassetfiles: + issue17660_v3.patch

messages: + msg216113
versions: + Python 3.4, - Python 3.5
2014-04-11 06:21:00eric.araujosetversions: + Python 3.5, - Python 3.4
nosy: + eric.araujo

messages: + msg215917

stage: needs patch -> patch review
2013-04-08 21:02:08michael.foordsetmessages: + msg186347
2013-04-08 18:17:07pitrousetnosy: + pitrou
messages: + msg186323
2013-04-08 13:26:19kushal.dassetfiles: + issue17660.patch
keywords: + patch
messages: + msg186301
2013-04-08 10:52:24kushal.dassetnosy: + kushal.das
messages: + msg186291
2013-04-08 10:48:09michael.foordcreate