in both places, make s a list and append terms to it then at the end return Add(*s). This guarantees that you are sending a SymPy object. right now you would send back an int if sz where 0.