Recordtype does not work as a drop-in replacement to namedtuple collection

September 10, 2017, at 08:33 AM

I'm pretty new to Python so forgive me if I'm missing something obvious. Originally I had a class that was subclassed by collections.namedtouple. I was my understanding that recordtype can be used as a drop-in replacement for someone who wants a mutable namedtuple. However when i went from this code:

class SplitResultsContainer(collections.namedtuple('SplitResultsContainer', _URI_COMPONENTS)):

to this code:

class SplitResultsContainer(recordtype.recordtype('SplitResultsContainer', _URI_COMPONENTS, default=None)):

one of my tests failed:

self.assertEquals(splituri('foo://'), ('foo', '', '/over/there', 'name=ferret', 'nose'))
AssertionError: SplitResultsContainer(scheme=foo,, path=/over/there, query=name=ferret, fragment=nose) != ('foo', '', '/over/there', 'name=ferret', 'nose')

I am creating a URI parser to teach myself Python. Any help regarding why the tuple does not match recordtype in my test would be very helpful, thanks!