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: Refer to types.SimpleNamespace in namedtuple documentation
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Rosuav, berker.peksag, docs@python, paul.moore, python-dev, vstinner
Priority: normal Keywords: easy, patch

Created on 2016-04-19 12:25 by paul.moore, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
collections.patch vstinner, 2016-04-19 13:44 review
Messages (9)
msg263733 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-04-19 12:25
People often look towards collections.namedtuple when all they actually want is "named attribute" access to a collection of values, without needing a tuple subclass, or positional access. In these cases, types.SimpleNamespace may be a better fit.

I suggest adding the following pointer to the top of the namedtuple documentation:

"""
For simple uses, where the only requirement is to be able to refer to a set of values by name using attribute-style access, the :ref:`types.SimpleNamespace` type may be a suitable alternative to using a namedtuple.
"""
msg263737 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-19 13:44
LGTM. I was going to push your sugestion when I saw that you are allowed to push yourself. See my attached patch:

* I fixed :ref:`types.SimpleNamespace` => you have to use :class:`...`
* I replaced "may be" with "can be" (I'm not confortable with "may", but it's up to you)
msg263740 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-04-19 14:02
Thanks Victor. I'll sort this out this evening when I get to my PC with access to the CPython repo.
msg263757 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-19 18:20
New changeset c3232d1d8ca0 by Paul Moore in branch 'default':
Mention types.SimpleNamespace in collections.namedtuple doc
https://hg.python.org/cpython/rev/c3232d1d8ca0
msg263759 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-19 19:22
types.SimpleNamespace is also available on Python 3.5, you may also modify Python 3.5 doc.
msg263761 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-04-19 19:54
Ah, thanks. I probably did the commit the wrong way round in that case, as I committed to tip. How should I do the commit into 3.5? (I'm also somewhat confused by the fact that hg describes the 3.5 branch as "inactive"...)
msg263763 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-19 20:14
I don't know what "inactive" means in Mercurial. Python 3.5 is
actively developed (maintained):
https://docs.python.org/devguide/#status-of-python-branches

> How should I do the commit into 3.5?

Update to 3.5 (hg up 3.5), transplant your change (hg transplant
c3232d1d8ca0). Fix if needed. I don't recall if you need to commit or
not (commit if you get the patch as local changes). Then update to
default (hg update default), and merge 3.5 (hg merge 3.5). Commit.

https://docs.python.org/devguide/devcycle.html#branches
msg263769 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-04-19 20:36
Or if you don't want to use any hg extension:

hg update 3.5
hg import --no-c http://bugs.python.org/file42520/collections.patch
hg commit
hg update default
hg merge 3.5
hg revert -ar default
hg resolve -am
hg commit

(Null merge (hg merge 3.5 and later) is step documented at https://docs.python.org/devguide/faq.html?#how-do-i-make-a-null-merge)
msg263779 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-19 22:00
New changeset 3115b6ce1006 by Paul Moore in branch '3.5':
Mention types.SimpleNamespace in collections.namedtuple doc
https://hg.python.org/cpython/rev/3115b6ce1006
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70992
2016-04-19 22:00:01python-devsetmessages: + msg263779
2016-04-19 20:36:16berker.peksagsetnosy: + berker.peksag
messages: + msg263769
2016-04-19 20:14:07vstinnersetmessages: + msg263763
2016-04-19 19:54:44paul.mooresetmessages: + msg263761
2016-04-19 19:22:09vstinnersetmessages: + msg263759
2016-04-19 18:22:02paul.mooresetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2016-04-19 18:20:11python-devsetnosy: + python-dev
messages: + msg263757
2016-04-19 14:02:06paul.mooresetmessages: + msg263740
2016-04-19 13:44:09vstinnersetfiles: + collections.patch

nosy: + vstinner
messages: + msg263737

keywords: + patch
2016-04-19 12:36:38berker.peksagsetkeywords: + easy
stage: needs patch
versions: + Python 3.5
2016-04-19 12:29:00Rosuavsetnosy: + Rosuav
2016-04-19 12:25:44paul.moorecreate