Jan Kaliszewski <z...@chopin.edu.pl> added the comment:

On python-ideas I have proposed an ABC being also a kind of a mix-in, 
potentially making namedtuple subclassing (with custom methods etc.) more 
convenient, e.g.:

    class MyRecord(namedtuple.abc):
        _fields = 'x y z'
        def _my_custom_method(self):
            return list(self._asdict().items())

or

    class MyAbstractRecord(namedtuple.abc):
        def _my_custom_method(self):
            return list(self._asdict().items())

    class AnotherAbstractRecord(MyAbstractRecord):
        def __str__(self):
            return '<<<{}>>>'.format(super().__str__())
 
    class MyRecord2(MyAbstractRecord):
        _fields = 'a, b'
 
    class MyRecord3(AnotherAbstractRecord):
        _fields = 'p', 'q', 'r'

Here is an experimental monkey-patcher adding the 'abc' attribute to namedtuple:

http://dpaste.org/T9w6/

I am not sure if it is worth preparing an actual patch based on it. If you 
think it is I could prepare one.

----------
nosy: +zuo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7796>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to