Message132363
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. |
|
Date |
User |
Action |
Args |
2011-03-27 20:40:01 | zuo | set | recipients:
+ zuo, rhettinger, amaury.forgeotdarc, pitrou, thead, eric.araujo, pwaller, srid |
2011-03-27 20:40:01 | zuo | set | messageid: <1301258401.58.0.340202583362.issue7796@psf.upfronthosting.co.za> |
2011-03-27 20:40:00 | zuo | link | issue7796 messages |
2011-03-27 20:40:00 | zuo | create | |
|