[Python-ideas] namedtuple baseclass
Chris Angelico
rosuav at gmail.com
Sun Jan 12 13:07:46 CET 2014
On Sun, Jan 12, 2014 at 10:55 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Jan 12, 2014 at 10:46:51PM +1100, Chris Angelico wrote:
>> On Sun, Jan 12, 2014 at 10:43 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> > It's a tuple. It already uses __getitem__ to return items indexed by
>> > position. Adding magic so that obj["fields"] is an alias for
>> > obj._fields is, well, horrible.
>>
>> It's only an alias in the simple version that I did there. If it were
>> to be used as a means of avoiding the _fields reserved name, it
>> wouldn't be an alias. But yes, it is somewhat magical. I was hunting
>> for an out-of-band way to get that sort of information.
>
> I still don't get how you think this solves the problem that the OP's
> use-case is to use isinstance() to identify namedtuples, then read
> _fields.
That was a slightly tangential comment stemming from Andrew Barnert's
remark that using _fields for a public API is quirky. (Which is why I
quoted him in my post.) This would no longer use an underscore name
for something public. That's all.
ChrisA
More information about the Python-ideas
mailing list