Sorry I don’ think I will have time to look into your specific code, considering it seems complicated. You can use standard debugger (e.g. pdb) to check the types at that line, and see where it went wrong.
Also, instead of modifying source, you can do a subclass, or just copying the def and make your own conv class, which will be much safer