Oh my bad, but still if you notice ,
Im calling C.Integral(factor) twice. In the first case, factor is essentially a function of x only , because the if statement executes only if factor is a function of x. 
    
    if x in variable and len(variable) == 1:

And in the second case, factor is a function of y only. So I don't think there is any harm.