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: Make namedtuple "verbose" and "rename" parameters into keyword only arguments
Type: enhancement Stage: commit review
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: gvanrossum, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-11-15 19:21 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
namedtuple_keywords.diff rhettinger, 2015-11-15 19:21 review
namedtuple_keywords_deprecate.patch serhiy.storchaka, 2015-11-15 20:25 review
Messages (13)
msg254689 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-15 19:21
This is a usability and readability improvement made possible by Python 3's keyword only arguments.

Usability is improved by getting a much less confusing response from the following mistake:

    namedtuple('Point', 'x', 'y')
                              ^--- invisibly goes to the "verbose" argument 

The "verbose" argument is normally used interactively (much like help() and dis()) or is used with a keyword argument, so it is unlikely that existing scripts will be much affected.  For the rare cases, the remediation is simple and improves code clarity (replacing "True" with "verbose=True").
msg254693 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-15 20:25
I like the idea. But this is backward incompatible change. I would first add a warning.

Here is a patch. Yes, the code looks a little cumbersome, but this is only for one or two releases.
msg254712 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-16 05:37
I don't think a warning is necessary because of what "verbose" does.
msg254716 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-16 06:27
Existing scripts can contain passing positional 'rename' argument: namedtuple('Point', 'x y', False, True).
msg254718 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-16 07:31
My judgment call is that the keyword-only change can be made directly, that the costs and clutter of deprecation and delay aren't worth in it this case, that the nature of the "verbose" and "rename" arguments puts this in the rare-to-non-existent category, that any remediation would be trivial (easier than shutting-off a warning), and that the user's come out ahead with the cleaner cut-over in this case.   There's no value in being pedantic on this one, some judgment is required.
msg254719 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-16 07:45
OK, leave it to you. But may be worth to add a versionchanged directive.
msg264942 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-06 06:57
Ping.

If the keyword-only changes can be made without deprecation, I would want to make such changes for json functions (issue18726). json.dump() takes 11 positional parameters!

Guido, what you say about this?
msg264984 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-05-06 15:45
I think such a change can be safely made in a feature release (say 3.6) without further deprecation. But not in a bugfix release (say 3.5.2).
msg264986 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-05-06 15:47
And by "safely" I mean that I don't mind if some code breaks when they upgrade to a new feature release.

FWIW the code most likely to break is code that wraps these functions with an identical interface.
msg264989 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-06 16:01
Then namedtuple_keywords.diff LGTM. But please document changes.
msg267783 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-08 05:12
Ping.
msg272765 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-08-15 14:48
Ping again.
msg272870 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-16 17:56
New changeset f086d6c9d9f6 by Raymond Hettinger in branch 'default':
Issue #25628:  Make namedtuple "rename" and "verbose" parameters keyword-only.
https://hg.python.org/cpython/rev/f086d6c9d9f6
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69814
2016-08-16 18:02:23rhettingersetstatus: open -> closed
resolution: fixed
2016-08-16 17:56:16python-devsetnosy: + python-dev
messages: + msg272870
2016-08-15 14:48:26serhiy.storchakasetmessages: + msg272765
2016-06-08 05:12:45serhiy.storchakasetmessages: + msg267783
2016-05-06 16:01:04serhiy.storchakasetassignee: rhettinger
messages: + msg264989
stage: patch review -> commit review
2016-05-06 15:47:39gvanrossumsetmessages: + msg264986
2016-05-06 15:45:30gvanrossumsetmessages: + msg264984
2016-05-06 06:57:22serhiy.storchakasetnosy: + gvanrossum
messages: + msg264942
2015-11-16 07:45:28serhiy.storchakasetmessages: + msg254719
2015-11-16 07:31:21rhettingersetmessages: + msg254718
2015-11-16 06:27:17serhiy.storchakasetmessages: + msg254716
2015-11-16 05:37:08rhettingersetmessages: + msg254712
2015-11-15 20:25:03serhiy.storchakasetfiles: + namedtuple_keywords_deprecate.patch

nosy: + serhiy.storchaka
messages: + msg254693

stage: patch review
2015-11-15 19:35:00rhettingersettitle: Make namedtuple "verbose" and "renanme" parameters into keyword only arguments -> Make namedtuple "verbose" and "rename" parameters into keyword only arguments
2015-11-15 19:21:13rhettingercreate