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

157
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://example.com:8042/over/there?name=ferret#nose'), ('foo', 'example.com:8042', '/over/there', 'name=ferret', 'nose'))
AssertionError: SplitResultsContainer(scheme=foo, authority=example.com:8042, path=/over/there, query=name=ferret, fragment=nose) != ('foo', 'example.com:8042', '/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!

READ ALSO