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.

Author conqp
Recipients bob.ippolito, conqp, eric.smith, rhettinger, steven.daprano
Date 2021-01-06.10:58:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609930729.04.0.0414635678077.issue42765@roundup.psfhosted.org>
In-reply-to
Content
Okay, I found the solution. Not using super() works:

from typing import NamedTuple


class Spamm(NamedTuple):

    foo: int
    bar: str

    def __getitem__(self, index_or_key):
        if isinstance(index_or_key, str):
            try:
                return getattr(self, index_or_key)
            except AttributeError:
                raise KeyError(index_or_key) from None

        return tuple.__getitem__(self, index_or_key)

    def keys(self):
        yield 'foo'
        yield 'bar'


def main():

    spamm = Spamm(12, 'hello')
    print(spamm.__getitem__)
    print(spamm.__getitem__(1))
    d = dict(spamm)
    print(d)


if __name__ == '__main__':
    main()

Result:

<bound method Spamm.__getitem__ of Spamm(foo=12, bar='hello')>
hello
{'foo': 12, 'bar': 'hello'}
History
Date User Action Args
2021-01-06 10:58:49conqpsetrecipients: + conqp, rhettinger, bob.ippolito, eric.smith, steven.daprano
2021-01-06 10:58:49conqpsetmessageid: <1609930729.04.0.0414635678077.issue42765@roundup.psfhosted.org>
2021-01-06 10:58:49conqplinkissue42765 messages
2021-01-06 10:58:49conqpcreate