[New-bugs-announce] [issue29357] New NamedTuple syntax silently ignores method definitions

Elazar Gershuni report at bugs.python.org
Tue Jan 24 02:14:54 EST 2017


New submission from Elazar Gershuni:

The following does not work as expected:
```
from typing import NamedTuple

class A(NamedTuple):
    a: int

    def __repr__(self):
        return 'some A'

    def spam(self):
        print('spam!')

>>> a = A(5)
>>> repr(a)  # should be 'some A'
'A(a=5)'
>>> a.spam()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'spam'
```

----------
components: Library (Lib)
messages: 286147
nosy: elazar, gvanrossum, rhettinger
priority: normal
severity: normal
status: open
title: New NamedTuple syntax silently ignores method definitions
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29357>
_______________________________________


More information about the New-bugs-announce mailing list