Nick Coghlan added the comment:
So that they can be returned from an API without breaking backwards
compatibility, named tuples are intentionally equivalent to the corresponding
ordinary tuple:
>>> from collections import namedtuple
>>> Pair = namedtuple("Pair", "x y")
>>> Pair(1, 2) == (1, 2)
True
Transitivity thus requires that two named tuples with different field names
also compare equal with each other:
>>> Pair2 = namedtuple("Pair2", "a b")
>>> Pair(1, 2) == (1, 2) == Pair2(1, 2)
True
>>> Pair(1, 2) == Pair2(1, 2)
True
So the field names on named tuples are just an access mechanism - they aren't
part of the value of the instances.
----------
nosy: +ncoghlan
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16279>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com