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: memoryview() constructor documentation error
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, demian.brecht, docs@python, felixxm, georg.brandl, miss-islington, skrah
Priority: low Keywords: easy, patch

Created on 2014-01-27 11:53 by larry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue20408.patch demian.brecht, 2015-02-26 07:44 review
Pull Requests
URL Status Linked Edit
PR 24431 merged felixxm, 2021-02-03 19:24
PR 26355 merged miss-islington, 2021-05-25 14:24
PR 26356 merged miss-islington, 2021-05-25 14:24
Messages (10)
msg209436 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-27 11:53
The documentation for the memoryview constructor says it takes memoryview(obj).  Oddly, memoryview accepts keyword arguments (for its one required value), and the name of the argument is "object", not "obj".
msg236641 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-02-26 01:42
I think it's plain daft having "object" as a keyword argument.  Is it too late to do anything about this, or could we go through a deprecation period, or what?
msg236653 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2015-02-26 07:44
> Oddly, memoryview accepts keyword arguments (for its one required value), and the name of the argument is "object", not "obj".

Positional parameters can also be treated as named arguments.

> I think it's plain daft having "object" as a keyword argument.

True, it's not best practice to override builtins with parameter names. In this case because memoryview is implemented in C, it doesn't suffer the same consequences as a Python implementation can. However at the very least, I do agree that it does seem a little odd from a user's standpoint. Also, the docs currently use "obj" rather than "object": https://docs.python.org/3/library/stdtypes.html#memoryview.

I've attached a patch that just changes the name of the parameter. Scanning through Github (primarily numpy and scipy), I wasn't able to find anyone making use of the parameter name.

As this does break backwards compatibility and is more of a cosmetic enhancement than a bug, it should only go into 3.5+.

The other option here, other than to just leave it as is, is to simply use Py_ParseTuple rather than PyArg_ParseTupleAndKeywords, but I'm not sure what the general consensus is on that (it seems to me that the preferred approach is the latter).
msg236973 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-03-01 19:13
I agree that "obj" would be nicer.  On the other hand we explicitly
test for "object" in the tests, help(memoryview) says "object" and pypy
accepts "object".

Also, I think there may be other instances in the tree where reserved
names are used for parameters.
msg267041 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-03 05:17
I think the safest solution is to change 'obj' to 'object' in memoryview documentation.
msg267082 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-06-03 09:10
Or pretend in the documentation that it's a positional arg and make it one later. There is a slight performance difference.

I agree with Damien that probably no one uses the keyword arg.
msg267083 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-06-03 09:11
Sorry, I meant *Demian*.
msg394358 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2021-05-25 14:24
New changeset d18e5dae914b1db49b25ed7729c07a535d1f0c52 by Mariusz Felisiak in branch 'main':
bpo-20408: Fix memoryview() signature in docs (GH-24431)
https://github.com/python/cpython/commit/d18e5dae914b1db49b25ed7729c07a535d1f0c52
msg394359 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2021-05-25 14:30
New changeset 05f8ad0c745016cd8b5bdbda4336688b80f45fd7 by Miss Islington (bot) in branch '3.10':
bpo-20408: Fix memoryview() signature in docs (GH-24431)
https://github.com/python/cpython/commit/05f8ad0c745016cd8b5bdbda4336688b80f45fd7
msg394360 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2021-05-25 14:30
New changeset 8accb8c8ccf371021cba5a2b91f5b7c711fa8149 by Miss Islington (bot) in branch '3.9':
bpo-20408: Fix memoryview() signature in docs (GH-24431)
https://github.com/python/cpython/commit/8accb8c8ccf371021cba5a2b91f5b7c711fa8149
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64607
2021-05-25 14:31:25berker.peksagsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.11, - Python 3.8
2021-05-25 14:30:51berker.peksagsetmessages: + msg394360
2021-05-25 14:30:18berker.peksagsetmessages: + msg394359
2021-05-25 14:24:50berker.peksagsetmessages: + msg394358
2021-05-25 14:24:44miss-islingtonsetpull_requests: + pull_request24948
2021-05-25 14:24:38miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24947
2021-03-12 17:55:38larrysetnosy: - larry
2021-03-12 17:53:42felixxmsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.5, Python 3.6
2021-02-03 19:24:48felixxmsetnosy: + felixxm

pull_requests: + pull_request23241
stage: needs patch -> patch review
2016-06-03 09:11:04skrahsetmessages: + msg267083
2016-06-03 09:10:12skrahsetmessages: + msg267082
2016-06-03 08:55:49BreamoreBoysetnosy: - BreamoreBoy
2016-06-03 05:17:12berker.peksagsetassignee: docs@python
components: + Documentation, - Interpreter Core
versions: + Python 3.6
keywords: + easy
nosy: + berker.peksag, docs@python

messages: + msg267041
stage: patch review -> needs patch
2015-03-01 19:13:55skrahsetnosy: + skrah
messages: + msg236973
2015-02-26 07:44:20demian.brechtsetfiles: + issue20408.patch

components: + Interpreter Core
versions: - Python 3.4
keywords: + patch
nosy: + demian.brecht

messages: + msg236653
stage: needs patch -> patch review
2015-02-26 01:42:50BreamoreBoysetnosy: + BreamoreBoy

messages: + msg236641
versions: + Python 3.5, - Python 3.3
2014-01-27 11:53:11larrycreate