Users of namedtuple: do you use the _source attribute?

Rick Johnson rantingrickjohnson at gmail.com
Mon Jul 17 22:27:59 EDT 2017


On Monday, July 17, 2017 at 12:20:04 PM UTC-5, Steve D'Aprano wrote:
> collections.namedtuple generates a new class using exec,
> and records the source code for the class as a _source
> attribute.  Although it has a leading underscore, it is
> actually a public attribute. The leading underscore
> distinguishes it from a named field potentially called
> "source", e.g. namedtuple("klass", ['source',
> 'destination']).

Although i understand the reasoning behind using the leading
underscore, the Python devs should have realized that anyone
who follows Pythonic convention [1] will ignore a symbol
that starts with an underscore . So if the intention is that
`_source` should be a part of the public API, then
obviously, defining it in "standardized private form" is
very unwise. 

But to answer your question, no, none of my code relies on
the `_source` attribute. So i really don't care what happens
to it.

[1] Which i would hope is a rather large group, and not just
another "Rick singleton".



More information about the Python-list mailing list