[issue20408] memoryview() constructor documentation error

Demian Brecht report at bugs.python.org
Thu Feb 26 08:44:20 CET 2015


Demian Brecht added the comment:

> 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).

----------
components: +Interpreter Core
keywords: +patch
nosy: +demian.brecht
stage: needs patch -> patch review
versions:  -Python 3.4
Added file: http://bugs.python.org/file38241/issue20408.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20408>
_______________________________________


More information about the Python-bugs-list mailing list