I think, this should go to sympy.core.compatibility.