[issue7796] No way to find out if an object is an instance of a namedtuple
Jan Kaliszewski
report at bugs.python.org
Sun Mar 27 22:40:01 CEST 2011
Jan Kaliszewski <zuo at 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 <report at bugs.python.org>
<http://bugs.python.org/issue7796>
_______________________________________
More information about the Python-bugs-list
mailing list