[issue29357] New NamedTuple syntax silently ignores method definitions

2017-01-24 Thread Ivan Levkivskyi

Ivan Levkivskyi added the comment:

This has been already reported in https://github.com/python/typing/issues/352 
and fixed in https://hg.python.org/cpython/rev/f100619e7137 and 
https://github.com/python/typing/pull/364

Now adding new methods works but overwriting existing special attributes raises 
AttributeError:

class A(NamedTuple):
x: int
def spam(self):  # this works
...
def _fields(self):  # this is an error (and also for __repr__ etc)

If you think that overwriting all special attributes should be allowed (or only 
some of them) then we could discuss this at python/typing tracker.

--
nosy: +levkivskyi
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29357] New NamedTuple syntax silently ignores method definitions

2017-01-23 Thread Elazar Gershuni

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 "", line 1, in 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com